简体   繁体   English

谁能帮我上传 PHP 块上传的 JS 代码

[英]Can anyone help me with the JS code for PHP chunk upload

I m trying to upload large files using chunk upload.我正在尝试使用块上传上传大文件。 Gone through a few stack queries and found this code, However, it works perfectly fine for files below 200mb but when I try to upload say 2GB file, it returns This site can't be reached - Connection was reset error page.通过一些堆栈查询并找到了此代码,但是,它对于 200mb 以下的文件非常有效,但是当我尝试上传 2GB 文件时,它返回无法访问此站点 - 连接已重置错误页面。

I know I missed the JS part which I couldn't able to figure it out.我知道我错过了我无法弄清楚的 JS 部分。

HTML goes as : 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>

Upload.php上传.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 .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

Please help me out with the JS code for the above php chunk upload.请帮我解决上述php块上传的JS代码。

Any help is greatly appreciated.任何帮助是极大的赞赏。

The limit on file size uploads is limited by a LOT more than just PHP.文件大小上传的限制不仅限于 PHP。 PHP has its limits, Apache has its limits, many web services have their own limits, and then you have the limit on the /tmp directory size which could be set by user permissions on a shared host. PHP 有其限制,Apache 有其限制,许多 Web 服务都有自己的限制,然后您对 /tmp 目录大小有限制,这可以由共享主机上的用户权限设置。 Not to mention just running out of hard drive space!更不用说硬盘空间不足了!

In your case,在你的情况下,

    #CHANGE THESE VALUES
    php_value memory_limit 500M
    php_value post_max_size 1000M
    php_value upload_max_filesize 500M
    
    #TO SOMETHING LIKE THIS DEPENDS ON YOUR REQUIREMENTS
    php_value memory_limit 2GB
    php_value post_max_size 2GB
    php_value upload_max_filesize 2GB

Also you can set these values in your php.ini ( my location is /etc/php/7.0/apache2/php.ini ) sometime service provider does not allow to override php.ini setting with the .htaccess settings您也可以在 php.ini 中设置这些值(我的位置是 /etc/php/7.0/apache2/php.ini )有时服务提供商不允许使用 .htaccess 设置覆盖 php.ini 设置

As you also mention chunk upload in your question, check this link you will find good answers here.由于您还在问题中提到了块上传,请查看此链接,您会在此处找到很好的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM