Jaká je HTML syntaxe pro stažení souboru?* Vyřešeno
Napsal: 12 pro 2012 19:19
Píšu web, ale mám tam soubory které by si mohly hned stáhnout a ne aby mě přesměroval např. na ulož.to
Jak to mám napsat?
Jak to mám napsat?
České diskuzní fórum o počítačích
https://pc-help.cnews.cz/
Kód: Vybrat vše
<?php
$file = 'slozka/soubor.txt';
ob_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file)); /* pokud ten soubor není ve složce, smaž to basename a dej tam jen $file */
readfile($file);
exit();
?>
PHP píše:<?php
$soubor = Str_Replace('../',null,$_GET['url']);
If(File_Exists($soubor)){
$zakazane = Array('stahni.php');
if(In_Array($soubor, $zakazane)){
$soubor = "zakazane.txt";
}
$obFile=ob_start();
Readfile($soubor);
Header("Content-Length:".ob_get_length());
Header("Content-Description: File Transfer");
Header("Content-Type: force-download");
Header('Content-Disposition: attachment; filename="' . $soubor . '"');
ob_end_flush();
}
Else
echo "Soubor " . $soubor . " nebyl nalezen<br>\n";
?>