0

Hi Guys,

I have an image upload script on my website however i got tired of uploading them one at a time so i decided to add multiple upload fields.

Now when i submit the form i get the "Incorrect format..." error message appear from my code below. When i remove the code that generates the error message i get the following warnings:

Warning: getimagesize(Array) [function.getimagesize]: failed to open stream: No such file or directory in /home/user/public_html/website.co.uk/upload_images.php on line 103

Warning: filesize() [function.filesize]: stat failed for Array in /home/user/public_html/website.co.uk/upload_images.php on line 104

Warning: copy(Array) [function.copy]: failed to open stream: No such file or directory in /home/user/public_html/website.co.uk/upload_images.php on line 114

Does anybody have any idea as to what could be wrong with my code? Iv been on this for nearly 4 days now and i just cant seem to figure it out. Im desperate for some help.

Any advice would be greatly appreciated.

Thanks

<?php 
session_start();

$id = $_SESSION['id'];

$connect = mysql_connect("localhost","leemp5_admin","p7031521");
mysql_select_db("leemp5_database");

$query = mysql_query("SELECT * FROM users WHERE id='$id'");
$row = mysql_fetch_assoc($query);
	
$username = $row['username'];

$submit = $_POST['submit'];

$type = $_FILES['image']['type'];
$size = $_FILES['image']['size'];
$max_size = "1000"; 
$width = "100"; 
$height = "100";
 
$error = array();

function make_thumb($image_name,$filename,$new_width,$new_height) 
{
	$ext=getExtension($image_name); 

	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) 
	$source_image=imagecreatefromjpeg($image_name);   

	if(!strcmp("png",$ext)) 
	$source_image=imagecreatefrompng($image_name);
	
	if(!strcmp("gif",$ext)) 
	$source_image=imagecreatefromgif($image_name); 

	$old_x=imageSX($source_image);
	$old_y=imageSY($source_image);   
	
	$ratio1=$old_x/$new_width; 
	$ratio2=$old_y/$new_height; 
	
	if($ratio1>$ratio2)
	{ 
		$thumb_width=$new_width; 
		$thumb_height=$old_y/$ratio1; 
	} 
	else 
	{ 
		$thumb_height=$new_height;
		$thumb_width=$old_x/$ratio2; 
	} 
  
	$destination_image=ImageCreateTrueColor($thumb_width,$thumb_height);   

	imagecopyresampled($destination_image,$source_image,0,0,0,0,$thumb_width,$thumb_height,$old_x,$old_y);   

	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
	{
		imagejpeg($destination_image,$filename); 
	}
	
	if(!strcmp("png",$ext)) 
	{
		imagepng($destination_image,$filename); 
	}
	
	if(!strcmp("gif",$ext)) 
	{
		imagegif($destination_image,$filename); 
	}

	imagedestroy($destination_image); 
	imagedestroy($source_image); 
}   


function getExtension($str)
{ 
	$i = strrpos($str,"."); 
	if (!$i) { return ""; } 
	$l = strlen($str) - $i; 
	$ext = substr($str,$i+1,$l); 
	return $ext; 
}   

if($submit) 
{ 
	$image=$_FILES['image']['name']; 

	if ($image) 
	{ 
		$filename = stripslashes($_FILES['image']['name']);   
		$extension = getExtension($filename); 
		$extension = strtolower($extension); 

		if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
		{ 
			$error[] = "Incorrect format! Please make sure your image is a .jpg, .jpeg, .png or .gif file.";
		} 
		else
		{ 
			$size = getimagesize($_FILES['image']['tmp_name']); 
			$sizekb = filesize($_FILES['image']['tmp_name']); 
  
			if ($sizekb > $max_size*1024) 
			{ 
				$error[] = "Your image is too big! The maximum upload size is 1MB.";
			}   
			else
			{
				$image_name=time().'.'.$extension; 
 
				$newname="uploads/" . $username . "/images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); 

				if (!$copied) 
				{ 
					$error[] = "There was an error uploading your image. Please try again!";
				} 
				else 
				{ 
					$thumb_name='uploads/' . $username . '/images/thumbs/thumb_'.$image_name; 
 					$thumb=make_thumb($newname,$thumb_name,$width,$height); 
				}
			}
		}
	}
	else
	{
		$error[] = "Please select an image to upload!";
	}

	if(empty($error))
	{
		echo "Upload Successfully!<br />"; 
		echo '<img src="'.$thumb_name.'">';
		mysql_query("INSERT INTO images VALUES ('','$username','$image_name','','','','','uploads/$username/images/$image_name','uploads/$username/images/thumbs/thumb_$image_name','$type','$size')");
	}
	else
	{
    	echo implode($error);
	}
}
?>
<form method="post" enctype="multipart/form-data" action="upload_images.php">
<input type="file" name="image[]" /><br />
<input type="file" name="image[]" /><br />
<input type="file" name="image[]" /><br />
<input type="file" name="image[]" /><br />
<input type="file" name="image[]" /><br />
<input type="file" name="image[]" /><br />
<input type="submit" name="submit" value="Upload">
</form>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by dietdew12z
0

I'm not sure I can get you an answer, but I think I can get you closer.

In line 89 is the first place you reference the $_FILES variable that was just posted but you don't have a file index. So instead of $_FILES[image][name] I believe it should be $_FILES[image][name][0] for the first file and '' '' [1] for the second.

I'm not familiar with using copy(from,to) in uploads so it may work. I use move_uploaded_file(from,to) and it works so I've never experimented. ;)

You might put your upload process in a loop and use the loop index for your file index. ( i.e. for ($i=0;$i<6;$i++) and then use $_FILES[image][name][$i] )

David

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.