码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • PHP 大文件分块上传 底层实现


    <?php
    class clsSliceUpload
    {
        private $_blockFile;       // 分块文件
        private $_blockIdx;       //  第几个文件块
        private $_blockTotal;     //  文件块总数
        private $_config ;
        private $_destination_path = '';//目的路径
        private $_tmp_upload_path = '';//临时路径
    
        /**
         *
         * @param $blockFile 分块文件
         * @param array $config 基础配置
         */
        public function __construct($blockFile,array $config = [])
        {
    
            $this->_blockFile = $blockFile;
            $this->_config    = $config;
            $this->init($this->_config);
            $this->moveFile();
        
        }
    
        /**
         * 基础初始化
         * @param $configs
         */
        private function init($configs){
            $this->_blockIdx   = $configs['blockIdx']; 
            $this->_blockTotal = $configs['blockTotal']; 
            $this->_tmp_upload_path = $configs['tmp_upload_path'];
            $this->_destination_path = $configs['destination_path']; //目的路径
        }
        //  移动文件
        private function moveFile()
        {
             move_uploaded_file($this->_blockFile, $this->_tmp_upload_path);
            // 保持存活状态
            $_SESSION['sess_time'] = time();
            //开始合并文件
            $this->mergeFile();
        }
    
        /**
         *
         */
        private function mergeFile(){
    
            $filepath = $this->_destination_path;
            $fp = fopen($filepath, 'ab');
            $blob = file_get_contents($this->_tmp_upload_path);
            fwrite($fp,$blob);
            fclose($fp);
            unlink($this->_tmp_upload_path);
    
        }
        
        public function api()
        {
            $data = [];
            if ($this->_blockIdx == $this->_blockTotal) {
                if (file_exists($this->_destination_path)) {
                    $data['file_path'] = $this->_destination_path;
                }
            } else {
                $data = [
                    'percent' =>number_format($this->_blockIdx*100/$this->_blockTotal,2),
                ];
            }
            echo clsFunction::json($data);
        }
    }
    ?>
  • 相关阅读:
    asp毕业设计——基于asp+access的学生论坛设计与实现(毕业论文+程序源码)——学生论坛
    创建并配置一个新的python环境
    android jni通过反射打印java类的所有方法
    RuntimeError: Cannot insert a Tensor that requires grad as a constant. 可能原因
    matlab simulink锂离子电池智能充电策略研究
    [NSSCTF 2nd]Math
    NNDL 实验六 卷积神经网络
    史蒂夫·乔布斯诞辰67周年,他的这些思想仍值得我们学习
    探花交友_第9章-我的功能实现
    高斯模糊滤镜
  • 原文地址:https://blog.csdn.net/qq_24946333/article/details/105406951
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号