PDA

View Full Version : دانلود فایل از طریق کد php



mohaghegh
دوشنبه 20 دی 1395, 14:49 عصر
با سلام
من صفحه ای طراحی کردم که بر روی یک کلید، کلیک میکنم یک فایل که اسم آن در دیتا بیس ذخیره شده است را میگیرد و آنرا دانلود میکند. این کد برای فرمت پی دی اف و زیپ درست کار میکند ولی وقتی عکس را دانلودمیکند موقع باز کردن عکس خطای Windows photo viewer cant open this piture because the file appears to be damged, corrupted, or is too larg را میدهد
این هم کد دانلود من


$filename = $_POST['hyperlink'];
$download_path = "download/navdata/";
// Make sure we can't download files above the current directory location.
if(eregi("\.\.", $filename)) die("I'm sorry, you may not download that file.");
$file = str_replace("..", "", $filename);
// Make sure we can't download .ht control files.
if(eregi("\.ht.+", $filename)) die("I'm sorry, you may not download that file.");
// Combine the download path and the filename to create the full path to the file.
$file = "$download_path$filename";
if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");
// Extract the type of file which will be sent to the browser as a header
$type = filetype($file);
// Send file headers
header("Content-type: $type");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');
// Send the file contents.
set_time_limit(0);
readfile($file);

مشکل از کجاست؟

mohaghegh
دوشنبه 20 دی 1395, 15:34 عصر
درست شد باید قبل از readfile این کدها رو اضافه میکردم
ob_clean();
flush();