I'm using the dropzone.js library but it's not working.

我正在使用dropzone.js库,但它不起作用。

In the upload script I count the files to see if it works:

在上传脚本中,我会计算文件是否有效:

$file_count = count($_FILES['file']['name']);
echo $file_count;

But it only prints 1 all the time (I tried uploading 2+).

但它只打印1(我尝试上传2+)。

HTML:

<form id="propForm" class="" name="" action="upload.php" method="POST" enctype="multipart/form-data">
    <div class="option img">
        <h4>Imagenes (m&#225;ximo 6):</h4>
        <div id="dropzone" class="dropzone">
        // hidden input is appended here
        </div>
    </div>
    // more inputs
    <input value="Subir" type="submit" name="submitIT">
</form>

Dropzone options:

$('div#dropzone').dropzone({
    url: 'upload.php',
    paramName: "file[]", // The array is initialized here but it's not working
    acceptedFiles: 'image/*',
    addRemoveLinks: true,
    parallelUploads: 6,
    maxFilesize: 6,
    maxFiles: 6,
    autoDiscover: false,
    autoProcessQueue: false,
    uploadMultiple: true,
    hiddenInputContainer: '#dropzone',

    init: function () {
        thisDropzone = this;
        thisDropzone.on("maxfilesexceeded", function(file) { thisDropzone.removeFile(file); });
        $("input[type=submit]").click(function(e){ 
            e.preventDefault();
            thisDropzone.processQueue();
        });
        this.on("successmultiple", function(files, response) {
            alert('works');
            $("form#propForm").submit();
        });
    }
});

Upload.php output:

1  // output for echo $file_count;
Notice: Uninitialized string offset: 0 // $filen = $_FILES['file']['name'][$i]; (inside a for)

EDIT: It was working, just that the files are uploaded first than the form, so I was getting 1 and the notice.

编辑:它工作,只是文件首先上传而不是表格,所以我得到1和通知。

1 个解决方案

#1


1

My problem is that I need to create a custom folder for the images (based on the data of the form) so it won't work because it first upload the files and then the form. If someone needs this too, I found this jquery plugin: it's more basic, it just converts an input type file in a preview area (you'll have to create or show one for each file but you can do this easily with jquery) but at least it works.

我的问题是我需要为图像创建一个自定义文件夹(基于表单的数据),所以它不会工作,因为它首先上传文件,然后上传表单。如果有人也需要这个,我发现这个jquery插件:它更基本,它只是在预览区域中转换输入类型文件(你必须为每个文件创建或显示一个,但你可以使用jquery轻松完成)但是至少它有效。

The above code will just work to first upload the files in the queue and then submit the form data so just make sure the upload script will handle both separately:

上面的代码只是首先上传队列中的文件然后提交表单数据,所以只需确保上传脚本将单独处理:

if ($_FILES['file']['error'] == 0) {
// move_uploaded_file (single file)
// or a for($i=0; $i < $file_count; $i++) (multiple files)
}

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
//filter the data and store it in db
}

更多相关文章

  1. 关注:PHP文件目录和文件本身的操作
  2. php exec文件从终端运行,而不是从浏览器运行
  3. log4php将不同级别的日志打印到不同的日志文件中
  4. PHP - 在外部服务器上读取文件?
  5. 仅在LARAVEL或AJAX中提交表单时,无需用户身份验证即可将文件上载
  6. PHP ZipArchive 实现压缩解压Zip文件
  7. 纯php文件不加结束标记的好处
  8. 大文件从指定行开始读取
  9. 找不到go-pear。bat文件PHP 5.5 Windows 7。

随机推荐

  1. android获取wifi信号强度
  2. Android ScrollView 内部控件 layout_mar
  3. android button 上添加图片
  4. [置顶] Android高手进阶教程(四)之----An
  5. android 自动化(1)
  6. 解决java.lang.RuntimeException: Unable
  7. Fiddler跟踪监控android数据包
  8. android 新增一個廣播偵聽USB設備的插拔
  9. Android中Toast的用法简介(转)
  10. Android M 指纹框架