dropzone.js不上传 [英] dropzone.js not uploading

查看:376
本文介绍了dropzone.js不上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过遵循教程在dropzon网站上设置了一个简单的dropzone.js: StarTutorial 。它显示正确的dropzone,当我把文件放入它会显示,但是当我尝试点击上传按钮什么也没有发生。
我正在使用这个html代码:

 <!DOCTYPE html> 
< html>
< head lang =en>
< meta charset =UTF-8>
< link href =css / style.csstype =text / css =stylesheet/>
< script src =js / dropzone.js>< / script>
< / head>
< body>
< div id =main>
< form action =upload.phpclass =dropzoneid =zone>< / form>
< / div>
< / body>





此PHP代码:

 <?php 
$ ds = DIRECTORY_SEPARATOR;
$ storeFolder ='uploads';

if(!empty($ _ FILES)){
$ tempFile = $ _FILES ['file'] ['tmp_name'];
$ targetPath = dirname(__FILE__)。 $ DS。 $ storeFolder。 $ DS;
$ targetFile = $ targetPath。 $ _FILES [文件] [名];
move_uploaded_file($ tempFile,$ targetFile);
}
?>


解决方案

前段时间,这是由于索引。 Dropzone同时上传多个文件。因此文件名在数组中。用foreach或forloop键读取文件。我在CodeIgniter中使用了这个方法:
$ b $ $ $ $ $ $ $ $ $ $ $ $ foreach $ _FILES [file] [error] as $ key => $ $ b $ if($ error == UPLOAD_ERR_OK){
$ tempFile = $ _FILES ['file'] ['tmp_name'] [$ key];

$ name = $ _FILES [file] [name] [$ key];
$ file_extension = end((explode(。,$ name))); #extra()来防止通知

$ targetPath = FCPATH。 $ storeFolder。 $ DS; // 4

$ file_new_name = uniqid()。 。。 $ FILE_EXTENSION;

$ targetFile = $ targetPath。 $ file_new_name; // 5

move_uploaded_file($ tempFile,$ targetFile); // 6
}
}


I set up a simple dropzone.js by following the tutorial on the dropzon website by StarTutorial. It shows the dropzone correctly and when I drop files into it the will show up but when I try to click the upload button nothing happens. I am using this html code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link href="css/style.css" type="text/css" rel="stylesheet"/>
    <script src="js/dropzone.js"></script>
</head>
<body>
    <div id="main">
        <form action="upload.php" class="dropzone" id="zone"></form>
    </div>
</body>

And this PHP code:

<?php
$ds          = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';

if (!empty($_FILES)) {
    $tempFile = $_FILES['file']['tmp_name'];
    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
    $targetFile =  $targetPath. $_FILES['file']['name'];
    move_uploaded_file($tempFile,$targetFile);
}
?>

解决方案

I had the same issue a while ago. It is due to indexing. Dropzone uploads multiple files at the same time. Thus file name is in array. Read the file using key with foreach or forloop. I used this in CodeIgniter:

foreach ($_FILES["file"]["error"] as $key => $error)  {
    if ( $error == UPLOAD_ERR_OK ) {                
        $tempFile = $_FILES['file']['tmp_name'][$key];

        $name = $_FILES["file"]["name"][$key];
        $file_extension = end((explode(".", $name))); # extra () to prevent notice

        $targetPath = FCPATH . $storeFolder . $ds;  //4

        $file_new_name = uniqid(). '.'. $file_extension;

        $targetFile =  $targetPath. $file_new_name  ;  //5

        move_uploaded_file($tempFile,$targetFile); //6    
    }
} 

这篇关于dropzone.js不上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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