Evo ti jedan file (koji postavis na server) koji ce ti omoguciti download fileova
<?php
$AllowedExtensions = array('pdf', 'jpg', 'doc', 'txt');
$DownloadFolder = 'files';
$FileName = str_replace(array('..', '~', '/', '\\', ':'), '', urldecode($_SERVER['QUERY_STRING']));
if(!realpath('./'.$DownloadFolder.'/'.$FileName))
die('Wrong File Name');
$Extension = substr($FileName, -3);
if(!in_array($Extension, $AllowedExtensions))
die('File Extension not allowed!');
$Lenght = filesize('./'.$DownloadFolder.'/'.$FileName);
header( "Content-type: application/x-{$Extension}" );
header( "Content-Disposition: attachment; filename=\"{$FileName}\"" );
header( "Content-Length: {$Lenght}" );
readfile( './'.$DownloadFolder.'/'.$FileName );
?>
Sacuvaj taj code u file recimo dnld.php, a sve fileove koje bih htio da downloadujes sa servera stavi u files folder.
Link kada budes pravio za download ce ti biti dnld.php?ime_filea
npr.
<a href='dnld.php?sample.pdf'>Test PDF</a>
|