twistednetadmin wrote:
I have made this script to upload pictures into a picturegallery on a
website.
The script works just as I expected, but with one huge flaw. It doesn't work
from every users computer.
I can upload pictures with no problem, but another user get's an
errormessage. the other user emailed the picture to me and I could upload it
with no errors.
Here's the script.
Screenshot upload
Only pictures with the .jpg extension and size 300kb or less will be
uploaded!
Imagenames should not contain quotes or any special signs!!
File:
Comment:
You may want to also do something like
if(filesize($filename) > 300) {
echo "File too large";
}
copy ($_FILES['guildimage']['tmp_name'],
"/guildimages/".$_FILES['guildimage']['name']) //Copy the image to
/guildimages
or die("Could not copy file"); //Or don't if it's wrong size or format
Here you should be using move_uploaded_file() instead of copy()
http://php.net/move_uploaded_file
$insertSQL = sprintf("INSERT INTO guildimages (guildimage_date,
guildimage_name, guildimage_comment, posted_by) VALUES (NOW(), '%s', '%s',
'%s')",
($_FILES['guildimage']['name']),
($_POST['guildimage_comment']),
($_SESSION['logname']));
$guildimage_upload = mysql_query($insertSQL) or die(mysql_error());
//insert all info to the DB
You probably want to do some checks above (before inserting), maybe use
http://php.net/manual/en/function.is-uploaded-file.php
echo "Result:\n";
echo "Filename: ".$_FILES['guildimage']['name']."\n";
echo "Filesize: ".$_FILES['guildimage']['size']." byte\n";
echo "Filtype: ".$_FILES['guildimage']['type']."\n";
echo "Congrats! It worked!\n";
}
else
{
echo "Result:\n";
echo "Now that didn't seem to work... \n
Did you try a wrong format or size? \n
File that failed--> (".$_FILES['guildimage']['name'].")";
}
}
?>
Can anyone see what's wrong? Since it works from some computers and not from
all?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php