【问题标题】:Problem uploading files greater than 10Mb in IE6在 IE6 中上传大于 10Mb 的文件时出现问题
【发布时间】:2018-05-10 17:55:52
【问题描述】:

嘿。此代码适用于大多数浏览器,甚至部分适用于 IE6。它上传的文件小于 10Mb(大约),但不会更大。该代码指定允许这些文件。

另外,请注意,似乎整个文件在被忽略之前似乎已传输到服务器。

网站在:www.mgxvideo.com/mgxcopy-alpha-3/,可以通过在购物车中添加商品,然后点击上传功能访问。想法?

这是表格:

<form enctype="multipart/form-data" action="upload_files.php?order_id=<?php echo $_GET['order_id'] ?>" method="POST">
    <table style="width:100%">
        <tr>
            <td valign="top">
                <span class="style1">Choose a file to upload: </span> 
            </td>
            <td valign="top">
                <input name="uploadedfile" type="file" />
            </td>
        </tr>
    </table>
    <input type="submit" value="Upload File" />
    <input type="hidden" name="action" value="add"/>
    <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
</form>

这是upload_files.php顶部的一行:

$upload_output = upload_file($customer_id, $_REQUEST['action'], $_GET['order_id'], $_FILES);

这里是upload_file() 代码:

function upload_file($customer_id, $action, $upload_id, $FILES)
{
    $target_path = "uploads/";

    $target_path = $target_path . $customer_id . '_' . $upload_id . '_' . basename( $FILES['uploadedfile']['name']); 
    $str_output = '';

    if ($action == 'del' and file_exists($_POST['filepath']))
    {
        delete_file($customer_id, $_POST['filepath']);
        $str_output = '<span class="style1">File successfully deleted. If you are done uploading files, ' .
                '<a href="#" onclick="self.close();">click here</a> to close this window.</span>';
        setcookie("upload_out_txt", $str_output, time() + 300);
        setcookie("upload_out_b", "1", time() + 300);
    } else if ($action == 'add')
    {
        if (count_uploads($customer_id, $upload_id) >= 2)
        {
            $str_output = '<span class="style1">Problem: You have reached the maximum allowed uploads for this particular order. Please delete a file before continuing.</span>';
            setcookie("upload_out_txt", $str_output, time() + 300);
            setcookie("upload_out_b", "1", time() + 300);
        } else if (file_exists($target_path))
        {
            $str_output = '<span class="style1">Problem: A version of the file you are trying to upload already exists. Please delete the file from out servers before uploading again.</span>';
            setcookie("upload_out_txt", $str_output, time() + 300);
            setcookie("upload_out_b", "1", time() + 300);
        } else if (move_uploaded_file($FILES['uploadedfile']['tmp_name'], $target_path)) 
        {
            insert_to_database('uploaded_files', array($customer_id, $upload_id, 'now()', $target_path));
            $str_output = '<span class="style1">Success. The file was successfully uploaded. If you are done, <a href="" onclick="window.close();">click here to close the window</a></span>';
            setcookie("upload_out_txt", $str_output, time() + 300);
            setcookie("upload_out_b", "1", time() + 300);
        } else
        {
            $str_output = '<span class="style1">There was an error uploading the file, please try again!</span>';
            setcookie("upload_out_txt", $str_output, time() + 300);
            setcookie("upload_out_b", "1", time() + 300);
        }
    }



    return $str_output;
}

这是我尝试实施修复后的 php.ini 文件:

extension_dir="/kunden/homepages/30/d93769495/htdocs/extensions";
extension=uploadprogress.so;
upload_max_filesize=150M;
post_max_size=210M;
max_input_time=1800;
file_uploads=1;
memory_limit=240M;
max_execution_time=1800;

【问题讨论】:

    标签: php apache upload internet-explorer-6


    【解决方案1】:

    检查php.ini中的以下设置:

    1. upload_max_filesize 需要大于 10 MiB (10M)。

    2. post_max_size需要至少比upload_max_filesize大40%。

    之所以需要这样做是因为一些旧的用户代理会使用 base64 编码上传,这会增加 37% 的数据开销。添加 mime 标题,其他 post 参数,有很多理由让它高于upload_max_filesize

    1. max_input_time 至少需要 900(15 分钟)。

    您希望给用户足够的时间来上传文件。

    【讨论】:

    • @montooner:您可能需要在配置更改后重新启动 Apache。
    【解决方案2】:

    这可能无法解决它,但在一个线程上我正在阅读它说 IE6 需要在文件名输入之前处理 MAX_FILE_SIZE 行。所以尝试将以下行移动到表单的顶部:

    <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
    

    我不知道它是否有效并且 IE6 要求按该顺序解析它,但这就是我正在阅读的线程所说的解决方案。

    同时检查您的 php.ini 最大文件大小和超时时间。

    【讨论】:

    • MAX_FILE_SIZE 对客户端完全没有影响。事实上,你可以直接删除它。
    • 不错,好像没有浏览器关注它。从某个论坛我读到:“MAX_FILE_SIZE 隐藏字段(以字节为单位)必须在文件输入字段之前,其值是接受的最大文件大小。这是对浏览器的建议,PHP 也会检查它。欺骗此设置浏览器端非常简单,因此永远不要依赖此功能阻止更大尺寸的文件。”
    猜你喜欢
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多