天天看點

PHP之HEADER隐藏檔案下載下傳路徑

說明:主要是利用readfile函數将檔案另存下載下傳

<?
     $file="material_upload/Adobe Dreamweaver CS5.zip";  //$file裡面必須是真實的下載下傳路徑
     if(file_exists($file)) {
         header('Content-Description: File Transfer');
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename='.basename($file));
         header('Content-Transfer-Encoding: binary');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         header('Content-Length: ' .filesize($file));
         ob_clean();
         flush();
         readfile($file);
         exit;
     }
?>