繁体   English   中英

如何通过dropzone取回上传的图像路径

[英]How to get back uploaded image path by dropzone

我正在尝试返回dropzone的成功功能,但是它不起作用。 我需要在图片上传页面上返回路径和图片名称...

我的代码:

<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>

并上传脚本:

$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'; }

我需要成功函数来返回上载图像的路径。 谢谢。

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) {

    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM