plupload - 块大小的问题

时间:2018-01-11 09:46:14

标签: javascript php jquery plupload

我刚开始使用plupload并尝试了基本示例和PHP分块示例。

当我将chunk_size保持到2048kb

时,这些似乎工作正常

但是,如果我增加此值,网页会显示文件已正确上传,但上传文件夹既不显示文件,也不显示非常小的文件。 (几kb)

这就是我定义了plupload的方法:

var uploader = new plupload.Uploader({
    runtimes : 'html5,silverlight,html4',
    browse_button: 'browse',
    multi_selection: false,
    url: 'upload.php',
    chunk_size: '2048kb',
    max_retries: 3
});

我的上传脚本使用他们的示例非常简单。

<?php

    if (empty($_FILES) || $_FILES['file']['error']) {
        die('{"OK": 0, "info": "Failed to move uploaded file."}');
    }

    $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
    $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;

    $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
    $filePath = "uploads/$fileName";


    // Open temp file
    $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
    if ($out) {
        // Read binary input stream and append it to temp file
        $in = @fopen($_FILES['file']['tmp_name'], "rb");

        if ($in) {
            while ($buff = fread($in, 4096))
                fwrite($out, $buff);
        } else
            die('{"OK": 0, "info": "Failed to open input stream."}');

        @fclose($in);
        @fclose($out);

        @unlink($_FILES['file']['tmp_name']);
    } else
        die('{"OK": 0, "info": "Failed to open output stream."}');


    // Check if file has been uploaded
    if (!$chunks || $chunk == $chunks - 1) {
        // Strip the temp .part suffix off 
        rename("{$filePath}.part", $filePath);
    }

    die('{"OK": 1, "info": "Upload successful."}');
    ?>

我在apache2 error_log中看不到任何错误或警告,所以我有点卡住了。

知道如何增加块大小并让它正常工作吗?

0 个答案:

没有答案