Здраствуйте подскажите как реализовать скачивание файла правильно.
Используемый мной код скачивает файл docx и внутри него не реальный текст а весь html документ страници на которой скачивается файл ((( если другой тип файла то то всеравно ошибка
PHP:
скопировать код в буфер обмена
if(isset($_GET['file']) and preg_match("/^[a-zA-Z0-9_\.\/\-]{0,50}\.(xml|txt|pdf|png|gif|jpg|jpeg|exe|doc|docx|xls|ppt|zip|)$/",$_GET['file'])) { switch ($extension) { case "txt": $ctype="text/plain"; $type = 'txt'; break; case "pdf": $ctype="application/pdf"; $type = 'pdf'; break; case "exe": $ctype="application/octet-stream"; $type = 'exe'; break; case "zip": $ctype="application/zip"; $type = 'zip'; break; case "rar": $ctype="application/rar"; $type = 'rar'; break; case "doc": $ctype="application/msword"; $type = 'doc'; break; case "docx": $ctype="application/msword"; $type = 'docx'; break; case "xls": $ctype="application/vnd.ms-excel"; $type = 'xls'; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; $type = 'ppt'; break; case "gif": $ctype="image/gif"; $type = 'gif'; break; case "png": $ctype="image/png"; $type = 'png'; break; case "jpeg": $ctype="image/jpg"; $type = 'jpeg'; break; case "jpg": $ctype="image/jpg"; $type = 'jpg'; break; default: $ctype="application/force-download"; } header('Content-type: '.$ctype); header('Content-Disposition: attachment; filename="document.'.$type.'"'); if(file_exists(Yii ::getPathOfAlias('webroot').'/file_perfomer/'.$_GET['file'])){ //readfile(Yii::getPathOfAlias('webroot').'/file_perfomer/'.$_GET['file']); echo file_get_contents(Yii ::getPathOfAlias('webroot').'/file_perfomer/'.$_GET['file']); }
|