Forum Moderators: coopster

Message Too Old, No Replies

PHP image upload question...

         

AlexLee

9:40 am on Feb 21, 2005 (gmt 0)

10+ Year Member



I have a code here for uploading images.
$file_realname = trim($_FILES['image']['name']);
$extension = strrchr($file_realname, '.'); //this varibale contain the extension in the form: .EXT (with dot)
$productNum = "12345";
$new_name = $productNum . $extension; //you have to add the extension to the new name...
if (move_uploaded_file($_FILES['image']['tmp_name'], $uploaddir . $new_name))
{
echo $file_realname." has been uploaded and was renamed to" .$new_name;
}
else
{
echo "Error in uploading! File selected may be invalid or it is too big for uploading.<br>Please choose a file within the filesize limit of 1MB.";
}

How do I check if the file is a valid file? The user is suppose to press "browse" at the form and a window will popup for the user to choose the file. But if I just type randomly into the textfield, the code doesn't catch any error and proceeds to "upload the file".

And how do I limit the type of files the user is able to upload?

RyanM

1:51 am on Feb 22, 2005 (gmt 0)

10+ Year Member




if (getimagesize($filename)) {
//do code here
}