PHP Tutorial, PHP Help, Javascript Tutorial, Javascript Help, MySQL Tutorial, MySQL Help,Personal Wishes, Images,Download Tutorials,MySQL Downloads,Download Softwares.
Wednesday, August 31, 2011
Restrict the file uploads using PHP
Below is the php code to restrict the file uploads for a particular type of files. As an example, I'm showing all the extension types in the "Allowed extensions" variable.
<?php
$allowedExtensions = array("txt","csv","htm","html","xml",
"css","doc","xls","rtf","ppt","pdf","swf","flv","avi",
"wmv","mov","jpg","jpeg","gif","png");
if ($_FILES['upload_file']['tmp_name'] > '') {
if (!in_array(end(explode(".",
strtolower($_FILES['upload_file']['name']))),
$allowedExtensions)) {
die($_FILES['upload_file']['name'].' is an invalid file type!<br/>'.
'<a href="javascript:history.go(-1);">'.
'<< Go Back</a>');
}
}
2 comments:
Good information Anil...
Thanks shashi :) ...let me know if anythings more that I can post which will be helpful for us.....
Post a Comment