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; } }

 

转载于:https://www.cnblogs.com/chy1000/p/4372566.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值