how to check that file exists or not
Moderator: General Moderators
how to check that file exists or not
i am using " browse file control " in my php form, how can i know that user selects valid file. It may be possible that user just type any fake string in "browse" button, so how can i validate this.
-
timgolding
- Forum Newbie
- Posts: 14
- Joined: Tue Jul 24, 2007 9:02 am
This is a function i built for validating an image upload.
Code: Select all
if(!empty($_FILES["uploadedfile"]))
{
if (!getimagesize($_FILES["uploadedfile"]["tmp_name"])) {
echo "file is not an image.";
}
elseif($_FILES['uploadedfile']['size']>1048576)
{
echo "This file is too large";
}
}
else
{
$uploaddir=$_SERVER['DOCUMENT_ROOT'];
$uploaddir.=basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $uploaddir))
{
echo "File uploaded! <br />";
echo $uploaddir;
}
else
{
echo "There was a problem when uploding the new file, please contact admin about this.";
}
}- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm