在HTML5中拖放多个文件?

时间:2013-01-18 13:01:56

标签: php javascript jquery html5 drag-and-drop

我已经有一个上传多个文件的系统(HTML,JS,PHP)。

现在,我有一个输入倍数。但是我想用Drag&使用$_FILES["uploadfile"]删除而不更改系统PHP是否可能?

HTML

<input type="file" name="uploadfile[]" multiple="" style="position: absolute; margin: -5px 0px 0px -175px; padding: 0px; width: 220px; height: 30px; font-size: 14px; opacity: 0; cursor: pointer; display: none; z-index: 2147483583; top: 83px; left: 333px;">

<div id="dropzone" style="border: 3px solid #DDD; width: 400px; height: 400px;"></div>

PHP

$uploaddir = 'uploads/';

$files = array();
foreach ($_FILES["uploadfile"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $path = $uploaddir . basename($_FILES['uploadfile']['name'][$key]);
        if (move_uploaded_file($_FILES['uploadfile']['tmp_name'][$key], $path)) {
            $files [] = array (
                'title' => $_FILES['uploadfile']['name'][$key],
                'url' => $path,
                'size' => $_FILES['uploadfile']['size'][$key]
            );
        }
    }
}

echo json_encode($files);

1 个答案:

答案 0 :(得分:0)

看一下这里,前端方面非常易于理解,可以轻松适应您的脚本

Source Code 实施

Demo 查看