zoukankan      html  css  js  c++  java
  • PHP上传大文件和处理大数据

    1. 上传大文件

            /* 以1.5M/秒的速度写入文件,防止一次过写入文件过大导致服务器出错(chy/20150327) */
            $is_large_file = false;
            if( strlen($xml_str)>=2097152 ){ //当文件大于2M
                $is_large_file = true;
                
                fwrite($fp, $pre, strlen($pre)); //写入头部
                $start = 0;
                while( $content=mb_strcut($xml_str,$start,1572864) ){
                    $start = $start + 1572864;
                    $writeResult = fwrite($fp, $content, strlen($content));
                    if( !$writeResult ){
                        unlink($filename);
                        break;
                    }
                    sleep(1);
                    unset($content);
                }
                unset($xml_str);
                fwrite($fp, $end, strlen($end)); //写入尾部
            }else{
                $content = $pre.$xml_str.$end;
                fwrite($fp, $content, strlen($content));
            }

    2. 处理大数据的加密

        //aes加密
        public function aesEncode_large($info) {
            //.....(省略部分代码)

        if(mcrypt_generic_init($cipher, $this->aesKey, $this->aesIv) != -1){ //$cipherText = mcrypt_generic($cipher, $beianInfo); //原普通的加密方式(chy/20150327) //处理大字符串加密。temp.text主要用于文件缓存(chy/20150327) $filename = B_ROOT."/admin/temp/temp.txt"; file_put_contents($filename,''); //将文件清空 $fp = fopen($filename, 'wb'); while( $content=mb_strcut($info,$start,104800) ){ $start = $start + 104800; $cipherTextCut = mcrypt_generic($cipher, $content); fwrite($fp, $cipherTextCut, strlen($cipherTextCut)); unset($cipherTextCut); unset($content); } mcrypt_generic_deinit($cipher); mcrypt_module_close($cipher); fclose($fp); return true; } else { return false; } }
  • 相关阅读:
    docker 简单使用
    apache 目录网站显示indexs
    MySQL索引失效的几种情况
    mysql 基本常用语句
    UNIX 版本
    B语言的发明者 Ken Thomson & C语言的发明者Dennis Ritchie
    My SQl 积累
    C# DGV多行选择
    C#中很模糊查询DGV中数据的两种方法
    网址
  • 原文地址:https://www.cnblogs.com/chy1000/p/4372566.html
Copyright © 2011-2022 走看看