【发布时间】:2021-01-14 17:55:20
【问题描述】:
我正在尝试使用块上传来上传大文件。 通过一些堆栈查询并找到此代码,但是,它对于 200mb 以下的文件非常有效,但是当我尝试上传 2GB 文件时,它返回 无法访问此站点 - 连接已重置 错误页面。
我知道我错过了我无法弄清楚的 JS 部分。
HTML 如下:
<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Upload Full Video</label>
<span class="pure-form-message"> * required</span>
<input type="file" name="video" class="file_multi_video" accept="video/*" id="stacked-email" style="width:60%;" placeholder="" />
</form>
上传.php
set_time_limit(0);
$file2=($_FILES['video']['name']);
$tmpfile = $_FILES['file']['tmp_name'];
$orig_file_size = filesize($tmpfile);
$target_file = 'images/videos/'. $_FILES['video']['name'];
$chunk_size = 100; // chunk in bytes
$upload_start = 0;
$handle = fopen($tmpfile, "rb");
$fp = fopen($target_file, 'w');
while($upload_start < $orig_file_size) {
$contents = fread($handle, $chunk_size);
fwrite($fp, $contents);
$upload_start += strlen($contents);
fseek($handle, $upload_start);
}
fclose($handle);
fclose($fp);
unlink($_FILES['file']['tmp_name']);
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
php_value memory_limit 500M
php_value post_max_size 1000M
php_value upload_max_filesize 500M
请帮我解决上述 php 块上传的 JS 代码。
非常感谢任何帮助。
【问题讨论】:
-
实际执行 chunked 上传的部分在哪里?您刚刚展示了一个普通表单,因此无需任何额外的客户端脚本/AJAX,这将让您正常上传。
-
@04FS 你能帮我提供那个代码吗?
-
如果您使用的是 Google Chrome,请尝试使用其他浏览器。
标签: javascript php .htaccess