Page 1 of 1

sometimes the easiest stuff is the hardest

Posted: Fri May 13, 2005 4:28 pm
by Jr
Ok... I have an ELSEIF statement that works fine with this...

Code: Select all

$file_type = $_FILESї'userfile']ї'type'];


...except every time it goes to this it stops.

Code: Select all

ELSEIF ( $file_type != &quote;image/gif&quote; OR $file_type != &quote;image/bmp&quote; OR $file_type != &quote;image/pjpeg&quote; ) // File_Type not JPG, BMP or GIF
		{
			print &quote;<table width='$titlewide' $border>&quote;;
				print &quote;<tr height='160px'>&quote;;
					print &quote;<td align='center'>&quote;;
							print &quote;<b>File type needs to be JPG, BMP or GIF.</b>&quote;;
							print &quote;<p>Want to go back to the <a href='member_manage.php?action=edit_avatar'>edit avatar</a> page?&quote;;
					print &quote;</td>&quote;;
				print &quote;</tr>&quote;;
			print &quote;</table>&quote;;
		}

Posted: Fri May 13, 2005 4:38 pm
by Skara
okiedokey. First, let's try making your code halfway readable:
>>btw, use php instead of code tags ^_^

Code: Select all

elseif ($file_type != "image/gif" || $file_type != "image/bmp" || $file_type != "image/pjpeg") // File_Type not JPG, BMP or GIF
{
	print("<table width='$titlewide' $border>
	       <tr height='160px'>
	       <td align='center'>
	       <b>File type needs to be JPG, BMP or GIF.</b>
	       <p>Want to go back to the <a href='member_manage.php?action=edit_avatar'>edit avatar</a> page?
	       </td>
	       </tr>
	       </table>");
}
1. Use || instead of OR
2. Use lowercase statements
3. Use one command when you can (only one print() here)
4. print() should have parans

Now then, as for your problem, this statement will always evaluate to true:

Code: Select all

elseif ($file_type != "image/gif" || $file_type != "image/bmp" || $file_type != "image/pjpeg")
why?
pseudocode:

Code: Select all

if the filetype isn't &quote;image/gif&quote;, then ok
else, if the filetype isn't &quote;image/bmp&quote;, then ok
...
you need to use && instead of || :

Code: Select all

elseif ($file_type != "image/gif" && $file_type != "image/bmp" && $file_type != "image/pjpeg")
pseudocode:

Code: Select all

if the filetype isn't &quote;image/gif&quote; AND
the filetype isn't &quote;image/bmp&quote; AND
...
then ok
Edit: goofed the tags. fixed.

Posted: Fri May 13, 2005 4:49 pm
by Jr
ok... then what did I "F" up with this one?

Code: Select all

$size = GetImageSize($_FILES['userfile']['name']);
(not sure how to get the image Height/Width of a not-yet-uploaded image.)

Posted: Sat May 14, 2005 1:38 am
by phpScott
don't think you can as php wouldn't be able to read the file properties until the file gets to the server where php can access it.

Posted: Sat May 14, 2005 7:20 pm
by s.dot
wouldn't

Code: Select all

$size[0]
$size[1]
etc work.. even if it is a temporary uploaded file?

Posted: Sun May 15, 2005 3:39 am
by phpScott
it will work on the temp file but that file has still been uploaded to the server just not moved yet and possible renamed.

RE

Posted: Sun May 15, 2005 8:28 pm
by harrisonad
Skara wrote:you need to use && instead of || :

Code: Select all

elseif ($file_type != "image/gif" && $file_type != "image/bmp" && $file_type != "image/pjpeg")
I use arrays for this situations to make it easy to debug

Code: Select all

$imgtypes = array('image/gif','image/bmp','image/pjpeg');
if(!in_array($file_type,$imgtypes){
  // do stuff ...
}