to all guru
how can i get the file extension name when i upload a file
I need this file to upload only (jpeg,jpg,gif)
to all guru
how can i get the file extension name when i upload a file
I need this file to upload only (jpeg,jpg,gif)
You could put the file types you want to allow into an array and check to make sure the file being uploaded is of this type or send an error message:
<?php
$types = array("image/gif","image/jpeg","image/jpg");
//If the Submit button was pressed do:
if(isset( $Submit )){
if (in_array($_FILES['imagefile']['type'],$types)){
// copy files and echo success...
}
// Else echo error message
else {
echo "Wrong Filetype! Couldn't copy.";
}
}
2 ways
this ones proably a bit more secure
$_FILES['userfile']['type']
The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.
http://uk.php.net/features.file-upload
or you can do this
$file = $_FILES['userfile']['name'];
$ext = explode(".", $file);
echo "extention of file is: $ext";
this peice of code above will work great for most files but will break if they have 2 or more . in the file name (eg it will break if a picture is uploaded called "blah.imageage.jpg")
Even better is [man]getimagesize[/man]. It won't be fooled by bogus file extensions or MIME types.