当我上传多个文件时会发生问题。我们说我上传了7个文件,有时只需要2次 - 所有7个文件。我还没有期待任何回报,只需使用dropzone并将文件移动到文件夹。
我减少了代码,所以直截了当:
<form action="upload.php" class="dropzone" id="my-dropzone"
method="POST" enctype="multipart/form-data">
<span class="glyphicon glyphicon-picture"></span>
</form>
使用Javascript:
Dropzone.options.myDropzone = {
acceptedFiles: 'image/*',
maxFilesize: 25, // MB
addRemoveLinks: true,
init: function() {
var myDropzone = this;
this.on("success", function(file, dataURL) {
//No return yet, so ignore this
});
}
};
upload.php的
$ds = DIRECTORY_SEPARATOR;
if (!file_exists("folder")) {
mkdir("../somefolder/", 0777, true);
}
$storeFolder = "../somefolder/";
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
}