var_dump() is NOT failing!
Look at this snippet…
$tempFile = $_FILES['userPhoto']['tmp_name'];
if (empty($errors)){
echo 'VAR_DUMP OF: getImageSize($tempFile)';
var_dump(getImageSize($tempFile));
exit();
Results in this successful output…
$Filename = MySpreadsheet.xls
$tempFile = /Applications/MAMP/tmp/php/phpWwNJAB
VAR_DUMP OF: getImageSize($tempFile)
boolean false
What is causing the Error (Technically it is a “Notification”) is this line of code…
if ($imageDetails = getimagesize($tempFile)){
But only when I try to upload my empty file called “00.txt”
Still doubt me? Look…
$tempFile = $_FILES['userPhoto']['tmp_name'];
if (empty($errors)){
// echo 'VAR_DUMP OF: getImageSize($tempFile)';
// var_dump(getImageSize($tempFile));
// exit();
if ($imageDetails = getimagesize($tempFile)){
When I try and upload “MySpreadsheet.xls” I get this…
is not an image
And when I try and upload “00.txt” I still get…
Notice: getimagesize() [function.getimagesize]: Read error! in /Users/user1/Documents/DEV/++htdocs/05_Debbie/members/upload.php on line 86
Call Stack
# Time Memory Function Location
1 0.0009 75000 {main}( ) ../upload.php:0
2 0.0020 81196 getimagesize ( ) ../upload.php:86
The latter one might be returning an empty string, but an empty string, empty array, 0, or null ALL == false – and they do not === false… which is why you should be doing the if statement on the ASSIGNMENT so that you don’t even TRY to use $imageData if the result is false… That’s where most of your issues lie, is you are assigning it, then trying to operate on it without ever testing it… TEST FIRST, if false, you have NO BUSINESS trying to use the result!
I get what you are saying, but I changed my code and that isn’t the issue…
As I’ve said several times here:
$width = $imageDetails[0];
$height = $imageDetails[1];
$imageType = $imageDetails['mime'];
SHOULD NOT EVEN BE ATTEMPTED if $imageDetals=getimagesize($filename) returns false… which is why you test that FIRST before trying to do ILLEGAL variable accesses.
It has been fixed…
Basically:
if ($imageDetails=getimagesize($filename)) {
// do whatever you want/need to do with imageDetails here
} else {
// false condition, you have NO business trying to use imagedetails for ANYTHING
// BECAUSE IT FAILED!
}
I didn’t fix my code last night because of SitePoint freaking out…
You aren’t trapping it that way, and that’s why it’s not working for you.
See above.
So to re-cap, the $10,000 question is “Why doesn’t getimagesize() return FALSE on the file 00.txt but does on other non-Image files??” And more so, how do I handle that annoying Notification that is causing all of the issues??
Debbie