开发者

PHP rejects image upload in some cases, but I can't figure out why

开发者 https://www.devze.com 2023-01-29 23:51 出处:网络
I have a process whereby I take a picture on a phone and upload it to a PHP script on my server. It usually works, but *sometimes the phone takes a picture tha开发者_StackOverflow中文版t has SOMETHIN

I have a process whereby I take a picture on a phone and upload it to a PHP script on my server.

It usually works, but *sometimes the phone takes a picture tha开发者_StackOverflow中文版t has SOMETHING about it that the PHP doesn't like. I have copied the image to my computer and attempted to upload it through a standard browser upload form but get the same error.

My question is, how do I find out what the PHP is not liking about the image? (it appears to be a perfectly legitimate JPG, just like all the others that DO work).

My PHP looks like this:

if ( move_uploaded_file( $_FILES[ 'file' ][ 'tmp_name' ], $folder . $fileName1 ) ) {
  echo "SUCCESS";       
}
else{           
 "FAIL:";
  foreach (getallheaders() as $name => $value) {
           echo "|$name: $value| ";
  }

}

I'd like to print and save some error info about what is going wrong here, but am not sure how to introduce what, in effect, would be a catch block in PHP.

All help appreciated.


The $_FILES array contains a field that describes any error that occurred: $_FILES['file']['error']. You can check them out here http://ca.php.net/manual/en/features.file-upload.errors.php


Could it be that the files you are trying to upload are too big?

<?php 
if($_FILES['file']['error']) { 
  $Errors .= $_FILES['file']['error'];
} else { 
  // process 
} 
?> 
0

精彩评论

暂无评论...
验证码 换一张
取 消