Monday, 20 May 2013

download and read file using php


PHP File Downloading:

    In php we can easily download file using header and easy and simple script to download file given below.
    php code
    <?php if($_REQUEST['c']) { $fnm="res/".$_REQUEST['c']; header('Content-Disposition: filename='.basename($fnm)); header('Content-Type: application/'.filetype($fnm)); header('Size='.filesize($fnm)); readfile($fnm); //echo file_get_contents($fnm); } //open server side directory (res) where file placed $od=opendir("res"); while($file=readdir($od)) { if($file!='.' and $file!=".." and $file!="Thumbs.db") { echo "&lt;a href='dwn.php?c=$file'&gt;$file&lt;/a&gt;&lt;br&gt;"; } } ?>

No comments:

Post a Comment