0

For some reason I can ONLY upload .JPEG but not .GIF, .BMP, .PNG

Can someone help fix this please? Is their something I did wrong?

<?php ini_set("memory_limit", "200000000"); ?>
<?php

if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {
	

	if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000))
	{
		
  
		$max_upload_width = 2592;
		$max_upload_height = 1944;
		  
		if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){
			$max_upload_width = $_REQUEST['max_width_box'];
		}    
		if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){
			$max_upload_height = $_REQUEST['max_height_box'];
		}	

		
		if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){	
			$image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);
		}		
		if($_FILES["image_upload_box"]["type"] == "image/gif"){	
			$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);
		}	
		if($_FILES["image_upload_box"]["type"] == "image/bmp"){	
			$image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);
		}			
		if($_FILES["image_upload_box"]["type"] == "image/x-png"){
			$image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);
		}
		

		$remote_file = "images/".$_FILES["image_upload_box"]["name"];
		imagejpeg($image_source,$remote_file,100);
		chmod($remote_file,0644);
	
	

		list($image_width, $image_height) = getimagesize($remote_file);
	
		if($image_width>$max_upload_width || $image_height >$max_upload_height){
			$proportions = $image_width/$image_height;
			
			if($image_width>$image_height){
				$new_width = $max_upload_width;
				$new_height = round($max_upload_width/$proportions);
			}		
			else{
				$new_height = $max_upload_height;
				$new_width = round($max_upload_height*$proportions);
			}		
			
			
			$new_image = imagecreatetruecolor($new_width , $new_height);
			$image_source = imagecreatefromjpeg($remote_file);
			
			imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
			imagejpeg($new_image,$remote_file,100);
			
			imagedestroy($new_image);
		}
		
		imagedestroy($image_source);
		
		
		header("Location: upload.php?upload_message=image uploaded&upload_message_type=success&show_image=".$_FILES["image_upload_box"]["name"]);
		exit;
	}
	else{
		header("Location: upload.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error");
		exit;
	}
}
?>
3
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by akira_lee
0

Can you post your HTML form? as you may have something along these lines

<input name="image" id="image" accept="image/jpeg" type="file">

As you see here it says:

accept="image/jpeg"

This mean that it will only accept jpegs from the start.

Also on lines 14 and 17 you are using the word 'and' rather than '&&' to add to your if statement

Edited by AdriftUniform: n/a

0

I don't have that in the HTML. Its mostly just the upload box and PHP commands.

<?php if(isset($_REQUEST['upload_message'])){?>
            <div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>">
            <?php echo htmlentities($_REQUEST['upload_message']);?>
            </div>
		<?php }?>


<form action="upload.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;">
<label>Image file, maximum 4MB. it can be jpg, gif, png (2592 x 1944 px max):</label><br />
          <input name="image_upload_box" type="file" id="image_upload_box" size="40" />
          <input type="submit" name="submit" class="small button white input" value="Upload Face" />     
     
     <br />
	<br />

     
      <label>Do not&nbsp; change values below:</label>
      <br />
      <input name="max_width_box" type="text" id="max_width_box" value="500" size="4">
      x      
      
      <input name="max_height_box" type="text" id="max_height_box" value="375" size="4">
      px.
      
      

<input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" />
          </form>




<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?>
<p>
	<img src="images/<?php echo $_REQUEST['show_image'];?>" />
</p>
0

I was also thinking that it might have to do something with Line 67

imagejpeg($new_image,$remote_file,100);

Cause its only jpeg their. But I tried it with bmp, gif, and Png, and still nothing.

0

in your form at line 10 I would add in:

accept="image/gif, image/jpeg, ..."

and so on for all of the image types you want to use.

See if that helps, I have noticed that on line 58 you have this code:

$image_source = imagecreatefromjpeg($remote_file);

Both this and the code

imagejpeg($new_image,$remote_file,100);

which you posted will only deal with jpeg, you need to modify this to accept all files types you want.

0

That didn't work. I should of posted the error I got before.

Warning: imagecreatefromgif() [function.imagecreatefromgif]: '/tmp/php74VzS0' is not a valid GIF file in /FOLDER/upload.php on line 26

Warning: imagejpeg(): supplied argument is not a valid Image resource in /FOLDER/upload.php on line 37

Warning: chmod() [function.chmod]: No such file or directory in /FOLDER/upload.php on line 38

Warning: getimagesize(images/youtubehd.gif) [function.getimagesize]: failed to open stream: No such file or directory in /FOLDER/upload.php on line 42

Warning: imagedestroy(): supplied argument is not a valid Image resource in /FOLDER/upload.php on line 66

Warning: Cannot modify header information - headers already sent by (output started at /FOLDER/upload.php:26)

Line 26

$image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);

Line 37-38

imagejpeg($image_source,$remote_file,100);
		chmod($remote_file,0644);

Line 66

imagedestroy($image_source);
0

I do not know then I am afraid, I have not come across these errors before, I apologise that I cannot be of any more help.

0

Hello,
I'm having the same problem, did you found a solution? Could you help me out?

thank you

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.