修改了PHP配置但是上传大文件依旧失败怎么办?

#推荐
修改了PHP配置但是上传大文件依旧失败怎么办?

2026-03-17 2
[!--dianshu--] C币
VIP折扣
    折扣详情
  • 体验VIP会员

    免费

  • 月卡VIP会员

    免费

  • 年卡VIP会员

    免费

  • 永久VIP会员

    免费

查看演示
下载不了?请联系网站客服提交链接错误!
TAG标签: 安装指导

#推荐
修改了PHP配置但是上传大文件依旧失败怎么办?

2026-03-17 php教程 9999 2
郑重承诺丨总裁主题提供安全交易、信息保真!
TAG标签:
安装指导
[!--dianshu--] C币
VIP权限详情
    会员权限详情
  • 体验VIP会员

    免费

  • 月卡VIP会员

    免费

  • 年卡VIP会员

    免费

  • 永久VIP会员

    免费

开通VIP尊享优惠特权
立即下载 等待添加 升级会员 最新活动
微信扫码咨询 微信扫码咨询

联系电话:18888888888

进入TA的商铺 联系官方客服
详情介绍

欢迎!我白天是个邮递员,晚上就是个有抱负的演员。这是我的网站。我住在天朝的帝都,有条叫做Jack的狗。

问题:

修改了PHPupload_max_filesize、post_max_size、memory_limit、max_execute_time等等配置,但是上传大文件依旧失败怎么办?

当然不能简单粗暴的将这几个参数调大,否则服务器会出现内存资源吃光是早晚的的问题。

JS方法

1.监听上传按钮的onchange事件

2.获取文件的FILE对象

3.把文件的FILE对象进行切割,并且附加到FORMDATA对象中

4.把FORMDATA对象通过AJAX发送到服务器

5.重复3、4步骤,直到文件发送完。

PHP方法

1.建立上传文件夹

2.把文件从上传临时目录移动到上传文件夹

//移动文件    private function moveFile(){        $this->touchDir();        $filename = $this->filepath.'/'. $this->fileName.'__'.$this->blobNum;        move_uploaded_file($this->tmpPath,$filename);    }

3.所有的文件块上传完成后,进行文件合成

private function fileMerge(){        if($this->blobNum == $this->totalBlobNum){            $blob = '';            for($i=1; $i<= $this->totalBlobNum; $i++){                $blob .= file_get_contents($this->filepath.'/'. $this->fileName.'__'.$i);            }            file_put_contents($this->filepath.'/'. $this->fileName,$blob);           $this->deleteFileBlob();        }    }

4.删除文件夹

//删除文件块    private function deleteFileBlob(){        for($i=1; $i<= $this->totalBlobNum; $i++){            @unlink($this->filepath.'/'. $this->fileName.'__'.$i);        }    }

5.返回上传后的文件路径

//API返回数据    public function apiReturn(){        if($this->blobNum == $this->totalBlobNum){                if(file_exists($this->filepath.'/'. $this->fileName)){                    $data['code'] = 2;                    $data['msg'] = 'success';                    $data['file_path'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['DOCUMENT_URI']).str_replace('.','',$this->filepath).'/'. $this->fileName;                }        }else{                if(file_exists($this->filepath.'/'. $this->fileName.'__'.$this->blobNum)){                    $data['code'] = 1;                    $data['msg'] = 'waiting for all';                    $data['file_path'] = '';                }        }        header('Content-type: application/json');        echo json_encode($data);    }

upload.html

<!doctype html><html><head>    <meta charset="UTF-8">    <meta name="viewport"          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">    <meta http-equiv="X-UA-Compatible" content="ie=edge">    <title>Document</title>    <style>        #progress{            width: 300px;            height: 20px;            background-color:#f7f7f7;            box-shadow:inset 0 1px 2px rgba(0,0,0,0.1);            border-radius:4px;            background-image:linear-gradient(to bottom,#f5f5f5,#f9f9f9);        }         #finish{            background-color: #149bdf;            background-image:linear-gradient(45deg,rgba(255,255,255,0.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,0.15) 50%,rgba(255,255,255,0.15) 75%,transparent 75%,transparent);            background-size:40px 40px;            height: 100%;        }        form{            margin-top: 50px;        }    </style></head><body><div id="progress">    <div id="finish" style="width: 0%;" progress="0"></div></div><form action="./upload.php">    <input type="file" name="file" id="file">    <input type="button" value="停止" id="stop"></form><script>    var fileForm = document.getElementById("file");    var stopBtn = document.getElementById('stop');    var upload = new Upload();     fileForm.onchange = function(){        upload.addFileAndSend(this);    }     stopBtn.onclick = function(){        this.value = "停止中";        upload.stop();        this.value = "已停止";    }     function Upload(){        var xhr = new XMLHttpRequest();        var form_data = new FormData();        // const LENGTH = 1024 * 1024;        const LENGTH = 10 * 10;        var start = 0;        var end = start + LENGTH;        var blob;        var blob_num = 1;        var is_stop = 0        //对外方法,传入文件对象        this.addFileAndSend = function(that){            var file = that.files[0];            blob = cutFile(file);            sendFile(blob,file);            blob_num  += 1;        }        //停止文件上传        this.stop = function(){            xhr.abort();            is_stop = 1;        }        //切割文件        function cutFile(file){            var file_blob = file.slice(start,end);            start = end;            end = start + LENGTH;            return file_blob;        };        //发送文件        function sendFile(blob,file){            var total_blob_num = Math.ceil(file.size / LENGTH);            form_data.append('file',blob);            form_data.append('blob_num',blob_num);            form_data.append('total_blob_num',total_blob_num);            form_data.append('file_name',file.name);             xhr.open('POST','./upload.php',false);            xhr.onreadystatechange  = function () {                var progress;                var progressObj = document.getElementById('finish');                if(total_blob_num == 1){                    progress = '100%';                }else{                    progress = Math.min(100,(blob_num/total_blob_num)* 100 ) +'%';                }                progressObj.style.width = progress;                var t = setTimeout(function(){                    if(start < file.size && is_stop === 0){                        blob = cutFile(file);                        sendFile(blob,file);                        blob_num  += 1;                    }else{                        setTimeout(t);                    }                },1000);            }            xhr.send(form_data);        }    } </script></body></html>

upload.php

<?php class Upload{    private $filepath = './upload'; //上传目录    private $tmpPath;  //PHP文件临时目录    private $blobNum; //第几个文件块    private $totalBlobNum; //文件块总数    private $fileName; //文件名     public function __construct($tmpPath,$blobNum,$totalBlobNum,$fileName){        $this->tmpPath =  $tmpPath;        $this->blobNum =  $blobNum;        $this->totalBlobNum =  $totalBlobNum;        $this->fileName =  $fileName;                 $this->moveFile();        $this->fileMerge();    }         //判断是否是最后一块,如果是则进行文件合成并且删除文件块    private function fileMerge(){        if($this->blobNum == $this->totalBlobNum){            $blob = '';            for($i=1; $i<= $this->totalBlobNum; $i++){                $blob .= file_get_contents($this->filepath.'/'. $this->fileName.'__'.$i);            }            file_put_contents($this->filepath.'/'. $this->fileName,$blob);           $this->deleteFileBlob();        }    }        //删除文件块    private function deleteFileBlob(){        for($i=1; $i<= $this->totalBlobNum; $i++){            @unlink($this->filepath.'/'. $this->fileName.'__'.$i);        }    }         //移动文件    private function moveFile(){        $this->touchDir();        $filename = $this->filepath.'/'. $this->fileName.'__'.$this->blobNum;        move_uploaded_file($this->tmpPath,$filename);    }         //API返回数据    public function apiReturn(){        if($this->blobNum == $this->totalBlobNum){                if(file_exists($this->filepath.'/'. $this->fileName)){                    $data['code'] = 2;                    $data['msg'] = 'success';                    $data['file_path'] = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['DOCUMENT_URI']).str_replace('.','',$this->filepath).'/'. $this->fileName;                }        }else{                if(file_exists($this->filepath.'/'. $this->fileName.'__'.$this->blobNum)){                    $data['code'] = 1;                    $data['msg'] = 'waiting for all';                    $data['file_path'] = '';                }        }        header('Content-type: application/json');        echo json_encode($data);    }         //建立上传文件夹    private function touchDir(){        if(!file_exists($this->filepath)){            return mkdir($this->filepath);        }    }} //实例化并获取系统变量传参$upload = new Upload($_FILES['file']['tmp_name'],$_POST['blob_num'],$_POST['total_blob_num'],$_POST['file_name']);//调用方法,返回结果$upload->apiReturn();

下载地址
  • 提取密码
  • 1561
  • 解压密码
  • DWQwdewq
    立即免费下载
    修改了PHP配置但是上传大文件依旧失败怎么办?
收藏 (15) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 ()

所有文章为演示数据,不提供下载地址,版权归原作者所有,仅提供演示效果!

CMS主题网 php教程 修改了PHP配置但是上传大文件依旧失败怎么办? /showinfo-48-23-0.html

我们只做高端Wordpress主题开发!

常见问题
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情
  • 最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用
查看详情

相关文章

帝国CMS二次开发 函数文件      PRinterror()/e/class/connect.phpline 132query()/e/class/db_sql.php line 10fetch1()/e/class/db_sql.php line 30fetch()/e/class/db_sql.php line 22checklevel()/e/class/functions.php line 3414insert_dolog()/e/class/functions.php line 3...
#推荐
2026-03-17 14 C币
帝国CMS8.0父子信息调用方      帝国CMS8.0版新增父子信息功能,让一条信息也能成为一个信息、一个栏目、一个专题、甚至一个网站。本文共有四个部分:一、父子信息功能使用流程。二、调用子信息:可以用索引灵动标签调用。三、父子信息列表访问地址的语法说明。四、进阶:调用当前父子信息...
#推荐
2026-03-17 4 C币
帝国CMS判断当前数据库是      有时候我们需要判断数据库是否包含某字段,就可以使用下面这段SQL语法,$fr=$empire-&gt;fetch1(&quot;SELECT COUNT(*) AS column_exists FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = &amp;#39;$infotb&amp;#39; AND COLUMN_NAME = &amp;#39;money&amp;#39;&quot;);if($fr[&amp;...
#推荐
2026-03-17 4 C币
Python开发一个ChatGPT GU      1、首先去下载这个ChatGPT库,用到的库是这个:https://github.com/acheong08/ChatGPT2、安装这个ChatGPT库:pip3 install revChatGPT==0.0.a423、同目录还需要一个“config.json”:{    &quot;session_token&quot;: &quot;&quot;,    &quot;cf_clearance&quot;: &quot;&quot;,    &quot;user_agent&quot;: &quot;
#推荐
2026-03-17 4 C币
使用CSS Grid Generator拖      如果你是CSS小白,不会使用复杂的UI框架,又需要开发一个响应式网站,那么我的站长站推荐你使用CSS Grid Generator,直接拖拽网格,就可以立即生成响应式CSS代码,复制到自己项目即可使用。使用方法1、首先根据你的项目需求,生成指定的列数和网格数量2、然后拖到...
#推荐
2026-03-17 3 C币
Playwright闲鱼智能监控机      项目介绍Playwright闲鱼智能监控机器人项目,基于 Playwright 和AI过滤分析的闲鱼多任务实时监控与智能分析工具,配备了功能完善的 Web 管理界面。可以实时按规则抓取闲鱼商品,垃圾佬的最爱。闲鱼智能监控机器人:https://github.com/dingyufei615/ai-goof...
#推荐
2026-03-17 3 C币
过年给网站加一对灯笼CSS      马上快过年了,给网站加一对红灯笼,这样才有过年的喜庆劲儿。灯笼是代码生成的无需图片,而且还会摆动。使用方法把HTML下面代码粘贴到网页BODY内任意位子都可以。灯笼的位子可以微调.deng-box的left和right数值。CSS代码&lt;!-- 灯笼代码 --&gt;&lt;div class=&quot;de...
#推荐
2026-03-17 3 C币
ajax上传文件进度条功能示      ajax上传文件时,有时比较耗时,需要在界面上显示下进度信息,获取ajaxSettings中的xhr对象,为它的upload属性绑定progress事件的处理函数前端代码&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta charset=&quot;utf8&quot;&gt;&lt;title&gt;test upload&lt;/title&gt;&lt;!--jquery--&gt;&lt;script src=&quot;h...
#推荐
2026-03-17 3 C币