douying3251 2015-11-20 11:27
浏览 69

多个图像上传在RAM上占用了大量空间

I added multiple file upload on my website, but I noticed, that uploaded files eat much RAM on the server and it does not decrease for 1-2 days. I think the reason is incorrect PHP code... I tried to unset all variables but it didn't help. That's my code:

 <?php
if(isset($_POST['upload'])){
  if(count($_FILES['files']['name']) > 0){
        for($i=0; $i<count($_FILES['files']['name']); $i++) {
            $tmpFilePath = $_FILES['files']['tmp_name'][$i];
            if($tmpFilePath != ""){
                $max_filesize = 10000288;
                if(filesize($_FILES['files']['tmp_name'][$i]) > $max_filesize) 
                    die('File is too large.'); 
                if($_FILES['files']['type'][$i] != "image/jpeg" AND $_FILES['files']['type'][$i] != "image/png")
                    die('This is not available format.');         
                $shortname = $_FILES['files']['name'][$i];
                $filePath = "img/uploaded_images/full/" .date('d-m-Y-H-i-s').'-'.$_FILES['files']['name'][$i];
                if(move_uploaded_file($tmpFilePath, $filePath)) {

                    $files[] = $shortname;
                    $tmpFilePath = NULL;
                    $allowed_filetypes = NULL;
                    $max_filesize = NULL;
                     $filePath = NULL;
                     $_FILES['files']['name'][$i] = NULL;
                     $shortname = NULL;
                     $_FILES['files']['tmp_name'][$i] = NULL;
                     unset( $tmpFilePath);
                     unset($allowed_filetypes);
                     unset($max_filesize);
                     unset($filePath);
                     unlink($_FILES['files']['name'][$i]);
                     unset($_FILES['files']['name'][$i]);
                     unset($shortname);
                     unset($_FILES['files']['tmp_name'][$i]);
                }
              }
        }

            $_FILES = NULL;
            unset($_FILES);
    } 
} ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?