doufuxing8691 2014-09-01 09:55
浏览 35
已采纳

too long

I'm trying to return success function of dropzone but it's not working. I need the path and image name back on image uploading page...

My code:

<body>
    <button id="submit-all">Submit all files</button>
    <form action="uploads.php" class="dropzone" id="my-dropzone"></form>

    <script>       
        Dropzone.options.myDropzone = {                        
            // Prevents Dropzone from uploading dropped files immediately
               addRemoveLinks: true,
               autoProcessQueue: false,
               maxFilesize:100,
               parallelUploads:5, 
               maxFiles:5,                          
               acceptedFiles: "image/*,.pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.openxmlformats-officedocument.presentationml.template, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.presentationml.slide, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.template, application/vnd.ms-excel.addin.macroEnabled.12, application/vnd.ms-excel.sheet.binary.macroEnabled.12,text/rtf,text/plain,audio/*,video/*,.csv,.doc,.xls,.ppt,application/vnd.ms-powerpoint,.pptx",                        
               init: function() {
                   var submitButton = document.querySelector("#submit-all"),
                       myDropzone = this; // closure

                       submitButton.addEventListener("click", function() {
                           myDropzone.processQueue(); // Tell Dropzone to process all queued files
                       });       
              }
        };
    </script>           
</body>

And Upload script:

$upload_dir = 'uploads'; 
    if (!empty($_FILES)) {                                           
        $tempFile = $_FILES['file']['tmp_name'];
        echo $tempFile;
        // using DIRECTORY_SEPARATOR constant is a good practice, it makes your code portable.
        $targetPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR;
        // Adding timestamp with image's name so that files with same name can be uploaded easily.
        $mainFile = $targetPath.time().'-'. $_FILES['file']['name'];

             move_uploaded_file($tempFile,$mainFile);
    } else { echo 'error: no file'; }

I need the success function to return the path of uploaded images. Thanks.

  • 写回答

1条回答 默认 最新

  • dongwei2983 2014-09-01 12:51
    关注
    myDropzone.processQueue();
    myDropzone.on("success", function(file,responsenew) {
        // alert(responsenew);
        var response = jQuery.parseJSON(responsenew);
        $('#image_update').remove();
        if(response.html==undefined || response.html==null) {
    
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿