Jump to content

File upload conditional statement help


neogemima

Recommended Posts

So I have a form that allows users to upload 3 files.  In my php page I have a conditional statement to test the files.  It's pretty large.  I want to make it so that it tests if the image is of a certain file type, certain size, or if it's not there (if the user has no file to upload).

 

The thing it doesn't do is allow the user to leave a file upload field blank if they do not have an image.  What should I add to this conditional statement to allow that?

 

	
<?php
if ((($_FILES['img1']['type'] == "image/gif") || ($_FILES['img1']['type'] == "image/jpeg") || ($_FILES['img1']['type'] == "image/pjpeg"))
&& (($_FILES['img2']['type'] == "image/gif") || ($_FILES['img2']['type'] == "image/jpeg") || ($_FILES['img2']['type'] == "image/pjpeg"))
&& (($_FILES['img3']['type'] == "image/gif") || ($_FILES['img3']['type'] == "image/jpeg") || ($_FILES['img3']['type'] == "image/pjpeg"))
&& ($_FILES['img1']['size'] <= 150000) && ($_FILES['img2']['size'] <= 150000)
&& ($_FILES['img3']['size'] <= 150000))
{
//code continues
?>

 

That and any way to trim this statement down a bit would be great.  Thanks ahead.

Link to comment
https://forums.phpfreaks.com/topic/157891-file-upload-conditional-statement-help/
Share on other sites

Use an array, then use a loop - http://www.phpfreaks.com/forums/index.php/topic,251778.msg1182671.html#msg1182671

 

You never repeat code when you have multiple same-type data, that is bad programming, unless you like typing (and debugging the typing errors) and changing each occurrence of the code every time you make a minor change such as which file types to allow.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.