My image upload script isn't working correctly
Posted: Thu Jul 09, 2009 3:10 pm
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.
If I remove lines 6 & 7 the script works but obviously doesn't limit the file size...
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);