Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Uploading binary files with a form.

Status
Not open for further replies.

sonnysavage

Programmer
May 29, 2002
130
US
The field name of my form is "image". When the form is submitted, part of my logic looks like this:
Code:
if ($image) {
	$imageinfo = getimagesize($image);
}

The strange thing is, on my Windows 98 machine (where I develop), the logic works just fine, if an image has not been specified, that code does not execute. On the remote server (Linux), the code inside that if block tries to execute, and throws an error because it tries to
Code:
getimagesize()
on an "empty" string.

Is anyone aware of a more reliable way to check this $image variable?

Thanks!
 
I have a solution. isset{} won't work because the variable is set when the form is submitted. file_exists() returns true if the string is null. I can't for the life of me figure out why, maybe it's a bug. I got the solution from one of the user notes for the fopen() function.

Here is what I am doing now:
Code:
$image_pointer = @fopen($image, "rb");
if ($image_pointer) {
    $imageinfo = getimagesize($image);
}

$image_pointer will only be set if $image is a valid file path. The '@' symbol suppresses errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top