Hi!
I develop an webpage and I would like to create an download section. I have an php code to download files, but I have tried it for many times, but it doesn't work. I see continuesly the error message, but the picture.jpg file is in the same directory than the download.php and the index.php. I don't know what the problem is.
The content of download.php:
<?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;
}
}
?>
content of the index.php:
<a href="download.php?file=picture.jpg">Download file</a>