2016-02-26 1 views
0

Я пытаюсь использовать плагин загрузчика jQuery на странице post_form.php, расположенной на панели администратора, для моего сайта, заменяющего мой текущий загрузчик. В конечном итоге я хочу, чтобы загрузчик был связан с post_form, где он динамически разрешал клиентам на моем сайте создавать сообщения с загрузкой изображений, музыки и видео файлов из их учетной записи администратора. Эти сообщения будут загружаться на соответствующие страницы профиля на основе клиента, который отправил сообщение.Проблема с загрузкой файла jQuery на почтовую форму моего сайта

Одна из проблем, с которой я сталкиваюсь, - это когда я вставляю часть кода загрузчика файла jQuery для кнопки отправки, появляется таблица предварительного просмотра, но все находится под кнопкой отправки и сдвигает другие поля в форме сообщения строки справа. Я хотел бы иметь плагин на моей странице почтовой формы, которая отображается над полями отправки, статуса и категории, как показано в демонстрации на сайте плагина jQuery. Следующее, что я пытаюсь сделать после этого, - убедиться, что файл jQuery UploadHandler.php объединен с моим текущим файлом postcontroller.php, чтобы использовать функции и функции плагина, сохраняя путь загрузки файлов в папку uploads/разорвать и подавать сообщение, сделанное через post_form, пользователю на странице профиля моего сайта на основе идентификатора клиента/пользователя созданного плаката, когда они нажимают кнопку отправки после заполнения формы.

Если вы кто-то может помочь мне в решении этой проблемы, я был бы очень признателен и благодарен вам за вашу помощь. Спасибо всем заблаговременно, и я надеюсь, что я сделал все ясно, поскольку я новый пользователь здесь.

Ниже приводится часть кода из JQuery File Uploader плагин на моем post_form

кода для 'Post Title', 'Description' и 'URL' текстовые поля размещены здесь

    <tr> 
         <th>Upload:</th> 
         <td width="250"> 
         <!-- The file upload form used as target for the file upload widget --> 
         <form id="fileupload" action="//jquery-file-upload.appspot.com/" method="POST" enctype="multipart/form-data"> 
         <!-- Redirect browsers with JavaScript disabled to the origin page --> 
         <noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript> 
         <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> 
         <div class="fileupload-buttonbar"> 
          <div class="fileupload-buttons"> 
           <!-- The fileinput-button span is used to style the file input field as button --> 
           <span class="fileinput-button"> 
           <span>Add files...</span> 
            <input type="file" name="files[]" multiple> 
           </span> 
           <button type="submit" class="start">Start upload</button> 
           <button type="reset" class="cancel">Cancel upload</button> 
           <button type="button" class="delete">Delete</button> 
           <input type="checkbox" class="toggle"> 
           <!-- The global file processing state --> 
           <span class="fileupload-process"></span> 
          </div> 
          <!-- The global progress state --> 
          <div class="fileupload-progress fade" style="display:none"> 
           <!-- The global progress bar --> 
           <div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div> 
           <!-- The extended global progress state --> 
           <div class="progress-extended">&nbsp;</div> 
          </div> 
         </div> 
         <!-- The table listing the files available for upload/download --> 
         <table role="presentation"><tbody class="files"></tbody></table> 
         </form> 
         </td> 
        </tr> 
        <?php if(isset($data['row'])){?> 
        <tr> 

код 'Отправить', 'Отмена' и 'Reset' кнопки размещены здесь

  <div class="clear"></div> 

      <!-- The blueimp Gallery widget --> 
      <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even"> 
       <div class="slides"></div> 
        <h3 class="title"></h3> 
        <a class="prev">‹</a> 
        <a class="next">›</a> 
        <a class="close">×</a> 
        <a class="play-pause"></a> 
        <ol class="indicator"></ol> 
       </div>  
      </div>   

     </div> 
     <!-- end content-table-inner ............................................END --> 
     </td> 
     <td id="tbl-border-right"></td> 
    </tr> 
    <tr> 
     <th class="sized bottomleft"></th> 
     <td id="tbl-border-bottom">&nbsp;</td> 
     <th class="sized bottomright"></th> 
    </tr> 
    </table> 
    <div class="clear">&nbsp;</div> 

</div> 
<!-- end content --> 
<div class="clear">&nbsp;</div> 
</div> 
<!-- end content-outer......END --> 
<!-- The template to display files available for upload --> 
<script id="template-upload" type="text/x-tmpl"> 
{% for (var i=0, file; file=o.files[i]; i++) { %} 
    <tr class="template-upload fade"> 
     <td> 
      <span class="preview"></span> 
     </td> 
     <td> 
      <p class="name">{%=file.name%}</p> 
      <strong class="error"></strong> 
     </td> 
     <td> 
      <p class="size">Processing...</p> 
      <div class="progress"></div> 
     </td> 
     <td> 
      {% if (!i && !o.options.autoUpload) { %} 
       <button class="start" disabled>Start</button> 
      {% } %} 
      {% if (!i) { %} 
       <button class="cancel">Cancel</button> 
      {% } %} 
     </td> 
    </tr> 
{% } %} 
</script> 
<!-- The template to display files available for download --> 
<script id="template-download" type="text/x-tmpl"> 
{% for (var i=0, file; file=o.files[i]; i++) { %} 
    <tr class="template-download fade"> 
     <td> 
      <span class="preview"> 
       {% if (file.thumbnailUrl) { %} 
        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a> 
       {% } %} 
      </span> 
     </td> 
     <td> 
      <p class="name"> 
       <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a> 
      </p> 
      {% if (file.error) { %} 
       <div><span class="error">Error</span> {%=file.error%}</div> 
      {% } %} 
     </td> 
     <td> 
      <span class="size">{%=o.formatFileSize(file.size)%}</span> 
     </td> 
     <td> 
      <button class="delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>Delete</button> 
      <input type="checkbox" name="delete" value="1" class="toggle"> 
     </td> 
    </tr> 
{% } %} 

линии сценария указывает на ссылки в Интернете, предоставленных в плагине размещены здесь

<script> 
/*jslint unparam: true, regexp: true */ 
/*global window, $ */ 
$(function() { 
    'use strict'; 
    // Change this to the location of your server-side upload handler: 
    var url = window.location.hostname === 'wmlmusicguide.com' ? 
       '//jquery-file-upload.appspot.com/' : 'server/php/', 
     uploadButton = $('<button/>') 
      .addClass('btn btn-primary') 
      .prop('disabled', true) 
      .text('Processing...') 
      .on('click', function() { 
       var $this = $(this), 
        data = $this.data(); 
       $this 
        .off('click') 
        .text('Abort') 
        .on('click', function() { 
         $this.remove(); 
         data.abort(); 
        }); 
       data.submit().always(function() { 
        $this.remove(); 
       }); 
      }); 
    $('#fileupload').fileupload({ 
     url: url, 
     dataType: 'json', 
     autoUpload: false, 
     acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, 
     maxFileSize: 999000, 
     // Enable image resizing, except for Android and Opera, 
     // which actually support image resizing, but fail to 
     // send Blob objects via XHR requests: 
     disableImageResize: /Android(?!.*Chrome)|Opera/ 
      .test(window.navigator.userAgent), 
     previewMaxWidth: 100, 
     previewMaxHeight: 100, 
     previewCrop: true 
    }).on('fileuploadadd', function (e, data) { 
     data.context = $('<div/>').appendTo('#files'); 
     $.each(data.files, function (index, file) { 
      var node = $('<p/>') 
        .append($('<span/>').text(file.name)); 
      if (!index) { 
       node 
        .append('<br>') 
        .append(uploadButton.clone(true).data(data)); 
      } 
      node.appendTo(data.context); 
     }); 
    }).on('fileuploadprocessalways', function (e, data) { 
     var index = data.index, 
      file = data.files[index], 
      node = $(data.context.children()[index]); 
     if (file.preview) { 
      node 
       .prepend('<br>') 
       .prepend(file.preview); 
     } 
     if (file.error) { 
      node 
       .append('<br>') 
       .append($('<span class="text-danger"/>').text(file.error)); 
     } 
     if (index + 1 === data.files.length) { 
      data.context.find('button') 
       .text('Upload') 
       .prop('disabled', !!data.files.error); 
     } 
    }).on('fileuploadprogressall', function (e, data) { 
     var progress = parseInt(data.loaded/data.total * 100, 10); 
     $('#progress .progress-bar').css(
      'width', 
      progress + '%' 
     ); 
    }).on('fileuploaddone', function (e, data) { 
     $.each(data.result.files, function (index, file) { 
      if (file.url) { 
       var link = $('<a>') 
        .attr('target', '_blank') 
        .prop('href', file.url); 
       $(data.context.children()[index]) 
        .wrap(link); 
      } else if (file.error) { 
       var error = $('<span class="text-danger"/>').text(file.error); 
       $(data.context.children()[index]) 
        .append('<br>') 
        .append(error); 
      } 
     }); 
    }).on('fileuploadfail', function (e, data) { 
     $.each(data.files, function (index) { 
      var error = $('<span class="text-danger"/>').text('File upload failed.'); 
      $(data.context.children()[index]) 
       .append('<br>') 
       .append(error); 
     }); 
    }).prop('disabled', !$.support.fileInput) 
     .parent().addClass($.support.fileInput ? undefined : 'disabled'); 
}); 
// Initialize the jQuery UI theme switcher: 
$('#theme-switcher').change(function() { 
    var theme = $('#theme'); 
    theme.prop(
     'href', 
     theme.prop('href').replace(
      /[\w\-]+\/jquery-ui.css/, 
      $(this).val() + '/jquery-ui.css' 
     ) 
    ); 
}); 
// Post Form Validate 
    $(document).ready(function() { 
     $('#postForm').validate({ 
      errorElement: "div", 
      rules: { 
       name: { required: true }, 
       details: { required: true }, 
       category: { required: true } 
      } 
     }); 
     $('#restform').click(function(){ 
      $('#postForm')[0].reset(); 
     }); 
    }); 
</script> 
+0

ли вы иметь возможность обрезать текст (или, по крайней мере, разделить его на абзацы)? А также работать с вашим кодом на минимальном примере, который все еще реплицирует вашу проблему? Поскольку в вашем вопросе слишком много текста и слишком много кода. – IanS

+0

Благодарю вас за любезную обратную связь и наблюдение. Мое извинение за это я надеюсь, что редактирование, которое я сделал, теперь лучше читается. Я попытался предоставить код в моментальных снимках, но сайт говорит, что у меня недостаточно репутации/учетных данных, чтобы сделать это пока.Будучи я новичком, я не знал, как наилучшим образом показать код наилучшим образом, без лишнего. –

ответ

0

Я был в состоянии получить JQuery файл-загрузчик, чтобы показать на странице post_form.php для моего сайт, включив

    <td colspan=2 width="100%">     
        <!-- The table listing the files available for upload/download --> 
        <table role="presentation"><tbody class="files"><textarea cols="60" rows="6"></textarea></tbody></table> 

        <div class="rfloat"> 

в начале кода файла загрузчика

<tr> 
 
\t \t \t \t \t \t \t \t \t \t \t \t <th valign="top">Upload:</th> 
 
\t \t \t \t \t \t <td colspan=2 width="100%"> \t \t \t \t \t 
 
\t \t \t \t \t \t <!-- The table listing the files available for upload/download --> 
 
\t \t \t \t \t \t <table role="presentation"><tbody class="files"><textarea cols="60" rows="6"></textarea></tbody></table> 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t <div class="rfloat"> 
 
\t \t \t \t \t \t <form> 
 
\t \t \t \t \t \t <label for="theme-switcher">Theme:</label> 
 
\t \t \t \t \t \t <select id="theme-switcher" class="pull-right"> 
 
\t \t \t \t \t \t \t <option value="black-tie">Black Tie</option> 
 
\t \t \t \t \t \t \t <option value="blitzer">Blitzer</option> 
 
\t \t \t \t \t \t \t <option value="cupertino">Cupertino</option> 
 
\t \t \t \t \t \t \t <option value="dark-hive" selected>Dark Hive</option> 
 
\t \t \t \t \t \t \t <option value="dot-luv">Dot Luv</option> 
 
\t \t \t \t \t \t \t <option value="eggplant">Eggplant</option> 
 
\t \t \t \t \t \t \t <option value="excite-bike">Excite Bike</option> 
 
\t \t \t \t \t \t \t <option value="flick">Flick</option> 
 
\t \t \t \t \t \t \t <option value="hot-sneaks">Hot sneaks</option> 
 
\t \t \t \t \t \t \t <option value="humanity">Humanity</option> 
 
\t \t \t \t \t \t \t <option value="le-frog">Le Frog</option> 
 
\t \t \t \t \t \t \t <option value="mint-choc">Mint Choc</option> 
 
\t \t \t \t \t \t \t <option value="overcast">Overcast</option> 
 
\t \t \t \t \t \t \t <option value="pepper-grinder">Pepper Grinder</option> 
 
\t \t \t \t \t \t \t <option value="redmond">Redmond</option> 
 
\t \t \t \t \t \t \t <option value="smoothness">Smoothness</option> 
 
\t \t \t \t \t \t \t <option value="south-street">South Street</option> 
 
\t \t \t \t \t \t \t <option value="start">Start</option> 
 
\t \t \t \t \t \t \t <option value="sunny">Sunny</option> 
 
\t \t \t \t \t \t \t <option value="swanky-purse">Swanky Purse</option> 
 
\t \t \t \t \t \t \t <option value="trontastic">Trontastic</option> 
 
\t \t \t \t \t \t \t <option value="ui-darkness">UI Darkness</option> 
 
\t \t \t \t \t \t \t <option value="ui-lightness">UI Lightness</option> 
 
\t \t \t \t \t \t \t <option value="vader">Vader</option> 
 
\t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t </form> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t   <!-- The file upload form used as target for the file upload widget --> 
 
<form id="fileupload" action="//jquery-file-upload.appspot.com/" method="POST" enctype="multipart/form-data"> 
 
    <!-- Redirect browsers with JavaScript disabled to the origin page --> 
 
    <noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript> 
 
    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> 
 
    <div class="fileupload-buttonbar"> 
 
     <div class="fileupload-buttons"> 
 
      <!-- The fileinput-button span is used to style the file input field as button --> 
 
      <span class="fileinput-button"> 
 
       <span>Add files...</span> 
 
       <input type="file" name="files[]" multiple> 
 
      </span> 
 
      <button type="submit" class="start">Start upload</button> 
 
      <button type="reset" class="cancel">Cancel upload</button> 
 
      <button type="button" class="delete">Delete</button> 
 
      <input type="checkbox" class="toggle"> 
 
      <!-- The global file processing state --> 
 
      <span class="fileupload-process"></span> 
 
     </div> 
 
     <!-- The global progress state --> 
 
     <div class="fileupload-progress fade" style="display:none"> 
 
      <!-- The global progress bar --> 
 
      <div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div> 
 
      <!-- The extended global progress state --> 
 
      <div class="progress-extended">&nbsp;</div> 
 
     </div> 
 
    </div> 
 
    <!-- The table listing the files available for upload/download --> 
 
    <table role="presentation"><tbody class="files"></tbody></table> 
 
</form> 
 
<br> 
 
<!-- The blueimp Gallery widget --> 
 
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even"> 
 
    <div class="slides"></div> 
 
    <h3 class="title"></h3> 
 
    <a class="prev">‹</a> 
 
    <a class="next">›</a> 
 
    <a class="close">×</a> 
 
    <a class="play-pause"></a> 
 
    <ol class="indicator"></ol> 
 
</div> 
 
<!-- The template to display files available for upload --> 
 
<script id="template-upload" type="text/x-tmpl"> 
 
{% for (var i=0, file; file=o.files[i]; i++) { %} 
 
    <tr class="template-upload fade"> 
 
     <td> 
 
      <span class="preview"></span> 
 
     </td> 
 
     <td> 
 
      <p class="name">{%=file.name%}</p> 
 
      <strong class="error"></strong> 
 
     </td> 
 
     <td> 
 
      <p class="size">Processing...</p> 
 
      <div class="progress"></div> 
 
     </td> 
 
     <td> 
 
      {% if (!i && !o.options.autoUpload) { %} 
 
       <button class="start" disabled>Start</button> 
 
      {% } %} 
 
      {% if (!i) { %} 
 
       <button class="cancel">Cancel</button> 
 
      {% } %} 
 
     </td> 
 
    </tr> 
 
{% } %} 
 
</script> 
 
<!-- The template to display files available for download --> 
 
<script id="template-download" type="text/x-tmpl"> 
 
{% for (var i=0, file; file=o.files[i]; i++) { %} 
 
    <tr class="template-download fade"> 
 
     <td> 
 
      <span class="preview"> 
 
       {% if (file.thumbnailUrl) { %} 
 
        <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a> 
 
       {% } %} 
 
      </span> 
 
     </td> 
 
     <td> 
 
      <p class="name"> 
 
       <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a> 
 
      </p> 
 
      {% if (file.error) { %} 
 
       <div><span class="error">Error</span> {%=file.error%}</div> 
 
      {% } %} 
 
     </td> 
 
     <td> 
 
      <span class="size">{%=o.formatFileSize(file.size)%}</span> 
 
     </td> 
 
     <td> 
 
      <button class="delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>Delete</button> 
 
      <input type="checkbox" name="delete" value="1" class="toggle"> 
 
     </td> 
 
    </tr> 
 
{% } %} 
 
</script> 
 
\t \t \t \t \t \t </td> 
 
\t \t \t \t \t </tr> 
 
\t \t \t \t \t <tr>

my post_form page with the jQuery fileuploader showing

Смежные вопросы