sometimes the easiest stuff is the hardest

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

sometimes the easiest stuff is the hardest

Post 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;;
		}
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post 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.)
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

wouldn't

Code: Select all

$size[0]
$size[1]
etc work.. even if it is a temporary uploaded file?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

RE

Post 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 ...
}
Post Reply