My image upload script isn't working correctly

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
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

My image upload script isn't working correctly

Post 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...
unibroue
Forum Newbie
Posts: 4
Joined: Thu Jul 09, 2009 3:09 pm

Re: My image upload script isn't working correctly

Post by unibroue »

Code: Select all

<input type="hidden" name="MAX_FILE_SIZE" value="500" />
 
?? in the form!
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: My image upload script isn't working correctly

Post by tomsace »

I didn't have it in the forn, but I have just tried it but it didn't have any effect.
Post Reply