web sayfasına php ile downloader dosya

0 Cevap php

Ben bir web sayfası geliştirmek ve ben bir indirme bölümü oluşturmak istiyorum. Ben dosyaları indirmek için bir php kodu var, ama birçok kez denedim, ama çalışmıyor. Ben continuesly hata mesajı görüyorum ama picture.jpg dosya download.php ve index.php daha aynı dizinde olduğunu. Ben sorunun ne olduğunu bilmiyorum.

Download.php içeriği:

<?php


if (isset($_GET[‘file’]) && basename($_GET[‘file’]) == $_GET[‘file’]) {

$filename = $_GET[‘file’];

} else {

$filename = NULL;

} 


$err = ‘<p style="color:#990000">Sorry, the file you are requesting is unavailable.</p>’; 

if (!$filename) {


echo $err;

} else {


$path = ‘downloads/’.$filename;


if (file_exists($path) && is_readable($path)) {


$size = filesize($path);
header('Content-Type: application/octet-stream');
header('Content-Length: '.$size);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');


$file = @ fopen($path, ‘rb’);

if ($file) {


fpassthru($file);
exit;

} else {

echo $err;

}

} else {

echo $err;

}

}

?>

index.php içeriği:

<a href="download.php?file=picture.jpg">Download file</a>

0 Cevap