- Forums
- Scripts
- How To Display File Extension From Uploaded File web form
this is a how to display show get file extension getting uploaded file extension type [1318], Last Updated: Sat May 18, 2024
wallpaperama
Wed Jul 11, 2007
1 Comments
810 Visits
like many websites, they offer their visitors to upload files such as images, photos, zip, documents, text, and more, its important to know what type of files you are allowing your visitors to upload to your site. for example, if i have a form for a user to upload an image file, i should have my script check to make sure its an image file and not a file that can harm your server.
so to get the file extension i can use the substr() strrpos() PHP functions to be able to get the type of file a user is uploading..
lets say the file name is called wallpaperama.jpg so this is how i would declare the value of my string:
$fileName = 'wallpaperama.jpg';
then i want to find out what are the characters after the . (dot) with this code:
$ext = substr($fileName, strrpos($fileName, '.') + 1);
and this is the complete script:
<?
$fileName = 'wallpaperama.jpg';
$ext = substr($fileName, strrpos($fileName, '.') + 1);
echo 'The file extension is: .'.$ext;
?>
to see the script in action all you have to do is copy and paste the complete code above to a text editor like notepad and save it as wallpaperama.com and upload to your website, then open it with your browser. NOTE: your website must have PHP, if your website doesn't have PHP, go to www.webune.com to sign up for PHP webshosting.
COURTESY: this tutorial guide was brought to you by www.webune.com
https://www.wallpaperama.com/forums/_lwwmww.html