簡體   English   中英

警告:getimagesize():文件名不能為空php

[英]Warning: getimagesize(): Filename cannot be empty php

我問了這個問題,發現PHP配置將我的上傳限制為2MB,因此我將其固定為3MB。 但是,我現在有另一個問題:我也在檢查圖像尺寸,如果圖像看起來超過3MB,則失敗,並拋出以下錯誤。 那么如何才能停止錯誤並由我自己而不是PHP配置檢查大小?

警告:getimagesize():文件名不能為空

這是代碼:

$size = $_FILES['image']['size'];
list($width, $height) = getimagesize($_FILES['image']['tmp_name']);
$minh = 400;
$minw = 600;
$one_MB = 1024*1024; //1MB
if($size > ($one_MB*3))// this is not checking the size at all, the last echo is what I get if I try to upload over 3mb.
{
  echo"File exceeds 3MB";
}
elseif ($width < $minw ) {
  echo "Image width shouldn't be less than 600px";
}
elseif ($height <  $minh){
  echo "Image height shouldn't be less than 400px";
}
else{
  if (move_uploaded_file($_FILES['image']['tmp_name'], $new_location)){
    //do something
  } 
  else{
    echo "Image is too big, try uploading below 3MB";
  }
}

看起來上傳有時出錯。 嘗試在getimagesize()之前添加一些錯誤處理:

if (!file_exists($_FILES['image']['tmp_name'])) {
    echo "File upload failed. ";
    if (isset($_FILES['upfile']['error'])) {
         echo "Error code: ".$_FILES['upfile']['error'];
    }
    exit;
}

很難說為什么失敗了,因為其中涉及許多參數。 錯誤代碼可能會給您提示。

否則,也許可以從這里開始閱讀: http : //de2.php.net/manual/en/features.file-upload.php

我也遇到了同樣的錯誤,請轉到php.ini並轉到第800行“ upload_max_filesize”。 選擇最大上傳文件大小,我將我的文件設置為4M,在我的實際網站代碼中,3mb之后我什么都不允許。 由於某些原因,使它們兩個相同的大小不起作用,PHP.ini必須比允許上傳的大小大至少1mb。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM