Page 1 of 1

My image upload script isn't working correctly

Posted: Thu Jul 09, 2009 3:10 pm
by tomsace
I have created an image upload script to allow a user to upload an image. It renames the image to the users unique username, but the problem is that when the script tries to limit the filesize to 500kb, it doesn't allow any file to upload even if it is under 500kb.
Would be grateful if anyone could spot the error.

Code: Select all

unset($imagename);
if(!isset($_FILES) && isset($HTTP_POST_FILES)) {
$_FILES = $HTTP_POST_FILES; }
if(!isset($_FILES['image_file'])) {
$imagename = basename($_FILES['image_file']['name']); }
if ($_FILES['image_file']['size'] > 64000) {
$error1 = "<font class='title'>Your avatar exceeded the 500kb limit.</font>"; }
 
if($error1 == '') {
$newimage = "user/images/" . $username . ".jpg";
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
 
If I remove lines 6 & 7 the script works but obviously doesn't limit the file size...

Re: My image upload script isn't working correctly

Posted: Thu Jul 09, 2009 3:36 pm
by unibroue

Code: Select all

<input type="hidden" name="MAX_FILE_SIZE" value="500" />
 
?? in the form!

Re: My image upload script isn't working correctly

Posted: Thu Jul 09, 2009 3:41 pm
by tomsace
I didn't have it in the forn, but I have just tried it but it didn't have any effect.