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

时间:2015-11-20 11:27:51

标签: php space ram

我在我的网站上添加了多个文件上传,但我注意到,上传的文件在服务器上占用了大量内存,并且在1-2天内没有减少。我认为原因是错误的PHP代码...我试图取消所有变量,但它没有帮助。那是我的代码:

 <?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 个答案:

没有答案