Dropzone.js-上传文件夹结构和单个文件 [英] Dropzone.js - upload folder structures and single files

查看:232
本文介绍了Dropzone.js-上传文件夹结构和单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用从 nuhil 到结构化文件夹上载器使用 dropzone.js 使文件夹/完整文件夹结构的上传成为可能。



上传文件夹的效果很好,没有无论文件夹中有多少个文件夹,依此类推。但是当我尝试上传单个文件时,它根本无法工作。



这是我以前上传的代码:

 <?php 

session_start();

$ ds = DIRECTORY_SEPARATOR;
$ storeFolder =‘../uploads/’。$_SESSION[’userid’]。’/’;

if(!is_dir($ storeFolder)){
mkdir($ storeFolder);
}

if(!empty($ _ FILES)){

$ tempFile = $ _FILES ['file'] ['tmp_name'];

$ targetPath = dirname(__FILE__)。 $ ds。 $ storeFolder。 $ ds;

$ fullPath = $ storeFolder.rtrim($ _ POST [’path’], /。);
$ folder = substr($ fullPath,0,strrpos($ fullPath, /));

if(!is_dir($ folder)){
$ old = umask(0);
mkdir($ folder,0777,true);
umask($ old);
}

if(move_uploaded_file($ tempFile,$ fullPath)){
die();
}否则{
死亡('e');
}
}
?>

我想我也知道问题所在,因为我尝试上传的文件始终称为 undefined 并且无法打开,似乎它也尝试为单个文件创建一个文件夹,但是由于没有文件夹,它只是尝试创建一个没有值的文件夹(参见 mkdir($ folder,0777,true); )行。所以我知道问题出在哪里,但是我不知道如何使它起作用。是否有人知道单个文件也可以正常工作?

解决方案

因为尝试上载单个文件

  this.on( sending,function(file){var name = file.fullPath; if(typeof(file.fullPath)=== undefined){name = file.name;} $ (#tmp-path)。html('< input type = hidden name = path value ='+ name +' />')}));  


I'm currently using the structured folder uploader from "nuhil" to make the upload of folders/complete folder structures possible with dropzone.js.

Uploading folders is working great, no matter how many folders are in the folder, and so on. But when I try to upload a single file, it's not working at all.

Here is the code I used to upload:

<?php

session_start();

$ds = DIRECTORY_SEPARATOR;
$storeFolder = '../uploads/'.$_SESSION['userid'].'/';

if (!is_dir($storeFolder)) {
    mkdir($storeFolder);
}

if (!empty($_FILES)) {

    $tempFile = $_FILES['file']['tmp_name'];

    $targetPath = dirname( __FILE__ ) . $ds . $storeFolder . $ds;

    $fullPath = $storeFolder.rtrim($_POST['path'], "/.");
    $folder = substr($fullPath, 0, strrpos($fullPath, "/"));

    if (!is_dir($folder)) {
        $old = umask(0);
        mkdir($folder, 0777, true);
        umask($old);
    }

    if (move_uploaded_file($tempFile, $fullPath)) {
        die();
    } else {
        die('e');
    }
}
?>

I think I also know what the problem is, as the file I try to upload is always called undefined and is not openable, it seems like it tries to make a folder for the single file as well, but as there is none, it just tries to make one with no value (see line mkdir($folder, 0777, true);). So I know what the problem is, but I have no Idea how to make it working. Does anybody have an idea, what to do, that single files are working as well?

解决方案

Because when you try to upload single file the "file.fullPath" is undefined, You can try file.name then by checking undefined.

this.on("sending", function(file) {
        var name = file.fullPath;
        if (typeof (file.fullPath) === "undefined") {
            name = file.name;
        }
$("#tmp-path").html('<input type="hidden" name="path" value="'+name+'" />')
});

这篇关于Dropzone.js-上传文件夹结构和单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆