[SOLVED] file uploading

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
JamesNZ
Forum Newbie
Posts: 2
Joined: Thu Jan 06, 2005 2:35 am

[SOLVED] file uploading

Post by JamesNZ »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Can anyone help with the following (details through post):

Code: Select all

<form action="p_addphotos.php" method="POST" name="addphoto" ENCTYPE="multipart/form-data">

<table border=0 cellpadding=0 cellspacing=0 width=100%>

<tr>
<td align=left valign=top><b>Thumbnail:</b></td>
<td align=left valign=top>

<INPUT TYPE="file" NAME="img1" SIZE="50"></p>
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="8000" />
The size of the thumbnail must be exactly 100 by 100 pixels and must be in the format of *.jpg, *.jpeg or *.gif

</td>
</tr>

<tr>
<td align=left valign=top><b>Photo:</b></td>
<td align=left valign=top>

<INPUT TYPE="file" NAME="img2" SIZE="50"></p>
The image must be in the format of *.jpg, *.jpeg or *.gif

</td>
</tr>
and the code to upload the files

Code: Select all

$uploaddir = 'photos/thumbnails/';
	$uploadfile1 = $uploaddir . $_FILES['img1']['name'];

	$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");
	$imageinfo = getimagesize($_FILES['img1']['tmp_name']);

	// upload the file only if the file type is gif or jpg.
	if(in_array(strtolower($_FILES['img1']['type']),$filetypes) && $imageinfo[0] = 100 && $imageinfo[1] = 100)
	{

	 // let us read all the files in the directory and rename the file, if exists.
	 if (file_exists($uploadfile1))
	 {
		$path_parts = pathinfo($uploadfile1);
		$uploadfile1 = $uploaddir.(substr($_FILES['img1']['name'],0,(strlen($_FILES['img1']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
	 }

	  if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile1))
	  {
		$FileSuccess1 = 1;
	  }
	  else
	  {
		$FileSuccess1 = 0;
	  }
	}

	$uploaddir = 'photos/';
	$uploadfile2 = $uploaddir . $_FILES['img2']['name'];

	$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");

	// upload the file only if the file type is gif or jpg.
	if(in_array(strtolower($_FILES['img2']['type']),$filetypes))
	{
	 // let us read all the files in the directory and rename the file, if exists.
	 if (file_exists($uploadfile2))
	 {
		$path_parts = pathinfo($uploadfile2);
		$uploadfile2 = $uploaddir.(substr($_FILES['img2']['name'],0,(strlen($_FILES['img2']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
	 }

	  if (move_uploaded_file($_FILES['img2']['tmp_name'], $uploadfile2))
	  {
		$FileSuccess2 = 1;
	  }
	  else
	  {
		$FileSuccess2 = 0;
	  }
	}
img1 uploads fine but img2 doesn't go into the if statement:

Code: Select all

if(in_array(strtolower($_FILES['img2']['type']),$filetypes))
no matter what image extension the file is.

Can anyone see the reason why? Getting really frustrating :(


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You seem to have a size restrictor on img2, check the error element of the $_FILES['img2'] array.
JamesNZ
Forum Newbie
Posts: 2
Joined: Thu Jan 06, 2005 2:35 am

Post by JamesNZ »

Managed to solve it myself - as you said it was to do with the size (<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="8000" />)
Post Reply