PHP无法上传大于3002 x 2893像素的图片宽度

时间:2015-04-02 15:34:24

标签: php upload

我有代码,由我必须修改的其他人编写。它不会上传宽度大于3002像素且高度大于2893像素的文件。

我是如何测试它的:我有两个不同的图像,有两种不同的文件大小(宽度:3002px,高度:2009px)。当我将它们设置为3003px宽度时,它们将不会上传,但如果我将它们的宽度设置为3002px,它们都将上传。

然后我旋转了他们没有上传的图像(宽度:2009px,高度:3002px)。然后我用他们的高度玩,发现如果我将高度设置为2893px(在这种情况下宽度将是1934px),它将上传,但如果我将高度设置为2894px,则不会。

这是我的代码:

error_reporting(0); 
$change=""; 
define ("MAX_SIZE","9999999999");

function getExtension($str) 
    { 
        $i = strrpos($str,"."); 
        if (!$i) { return ""; } 
        $l = strlen($str) - $i; 
        $ext = substr($str,$i+1,$l); 
        return $ext; 
    }
$errors=0;

if($_SERVER["REQUEST_METHOD"]=="POST") 
    { 
      $image=$_FILES["img_1"]["name"]; 
      $uploadedfile = $_FILES["img_1"]['tmp_name'];
        if ($image) 
          { 
            $filename = stripslashes($_FILES["img_1"]['name']);
            $extension = getExtension($filename); 
            $extension = strtolower($extension);
              if ( ($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
                {
                  $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; 
                } 
              else 
                { 
                  if($extension=="jpg" || $extension=="jpeg" ) 
                    { 
                      $uploadedfile = $_FILES["img_1"]['tmp_name'];
                      $src = imagecreatefromjpeg($uploadedfile); 
                    } 
                  else if($extension=="png") 
                    { 
                      $uploadedfile = $_FILES["img_1"]['tmp_name'];
                      $src = imagecreatefrompng($uploadedfile); 
                    } 
                  else 
                    { 
                      $src = imagecreatefromgif($uploadedfile); 
                    } 
                echo $scr;
                list($width,$height)=getimagesize($uploadedfile);
                $newwidth=700; 
                $newheight=($height/$width)*$newwidth;
                $tmp=imagecreatetruecolor($newwidth,$newheight);
                $newwidth1=150; 
                $newheight1=($height/$width)*$newwidth1;
                $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
                imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
                imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height);
                $stamp = imagecreatefrompng('img/stamp.png');
                $marge_right = 10;
                $marge_bottom = 10;
                $sx = imagesx($stamp);
                $sy = imagesy($stamp);
                imagecopy($tmp, $stamp, $newwidth - $sx - $marge_right, $newheight - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
                $filenameb = "img_big/big_".(rand(0, 99999999))."."."$extension"; $filename1 = "img_tmb/small_".(rand(0, 99999999))."."."$extension";
                imagejpeg($tmp,$filenameb,100); 
                imagejpeg($tmp1,$filename1,100); 
                imagedestroy($src); 
                imagedestroy($tmp); 
                imagedestroy($tmp1); 
                imagedestroy($stamp);
          } 
      } 
  }
if(isset($_POST['Submit']) && !$errors) 
  { 
    $change=' <div class="msgdiv">Image Uploaded Successfully!</div>'; 
  }

$img_1b = $filenameb; 
$smollimg_1 = $filename1; 
unset($filename); 
unset($filename1);

我不知道MAX_SIZE指的是什么。也许代码中存在一些缺陷,可能是服务器端问题?

1 个答案:

答案 0 :(得分:0)

(代表OP发布)

我增加了memory_limit并且它有效。因此,如果upload_max_filesizepost_max_size不起作用,请尝试增加memory_limit