Hi, Can any one sort me out on how to allow for a script to download files of only a particular extension, not all file types are allowed. Here is the code: http://www.pasteit.in/131 Thank you.
$allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // executables 'exe' => 'application/octet-stream', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', // audio 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', // video 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo', 'xml' => 'application/xhtml+xml' ); Code (markup): That portion of the code is where you specify what different file types you want to be able for download, just chose the ones you want to allow for download and remove the rest. Save the source to a php file and lets call it download.php, then what you want to do is save this file into the directory that all of your downloadable files are in. You can if you choose to advance the script to make it so that you can store this file outside of the download files directory, now to download you have to use this file to call all of your downloads. http://www.yourdomain.com/mydownloads/download.php?f=myfile.zip Code (markup): Calling the file above will allow you to download specific file types using this script. <?php $allowed_ext = array ( // archives 'zip' => 'application/zip', // documents 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // executables 'exe' => 'application/octet-stream', // images 'gif' => 'image/gif', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', // audio 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', // video 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mov' => 'video/quicktime', 'avi' => 'video/x-msvideo', 'xml' => 'application/xhtml+xml' ); if (!isset($_GET['f']) || empty($_GET['f'])) { die("Please specify file name for download."); } $fname = basename($_GET['f']); $fsize=stat($fname); //Now I need to check the file type and allow only the approved types I specify above to download. header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Type: $mtype"); header("Content-Disposition: attachment; filename=\"$fname\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . $fsize[6]); @readfile($fname); ?> PHP: If you want to look into any other ways I suggest looking into something that works with .htaccess so that it could govern the hole site if you choose to not take this route.