Diskuze: Download souborů ne/funguje
V předchozím kvízu, Online test znalostí PHP, jsme si ověřili nabyté zkušenosti z kurzu.
Zobrazeno 2 zpráv z 2.
V předchozím kvízu, Online test znalostí PHP, jsme si ověřili nabyté zkušenosti z kurzu.
Mas tam primy vstup post, coz by profik nikdy neudelal.
Nemas tam obclean, start, to tam zanasi kazdou chybu. Coz odstrani nezadouci
vypsane texty, znaky pred vypisem souboru.
Mas tam funkce v okamziku, kdy precujes s header. Pokud u nektere nastane chyba,
tak se ti muze cela hlavicka rozdrbat.
Neukoncujes program pri stazeni, takze, za souborem mas mozna vypsany i htm
formular.
Pozn: Zruseni kesovani, ktere tam mam ja, neni dulezite. U mne jo, ja potrebuji,
aby se mi to nekesovalo, ikdyz je nazev souboru stejny, protoze jde o exporty z
programu.
Pozn2. Mas tam pouziti funkce pri vypisu html kodu. To ti muze delat pri kusy.
Lepsi by bylo zpracovat php predem a vypisovat jen data, promenou. Myslim ten
for-cyklus pro vypis souboru.
Pozn3. Nemel bys vypisovat seznam vsech souboru na disku. Muzes tam omylem
nahrat nejaky php kod a hacker si pak ten soubor muze stahnout, kdyz vi jeho
nazev. Nebo mu to tvuj program dovoli.
Tohle mam v programech ja.
ob_clean();
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: '.$charset);
header('Content-Type: '.$type.'; charset='.$charset);
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.$size);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//header("Cache-Control: no-store, no-cache");
header('Pragma: public');
header('Expires: 0');
echo $content;
exit();
---
$path = $this->path;
$charset = isset($arg['charset']) ? $arg['charset'] : "UTF-8";
$file = isset($arg['file']) ? basename($arg['file']) : '';
$type = !isset($arg['type']) ? 'application/octet-stream' : $type; // text/csv text/plain application/vnd.ms-excel application/download
ob_clean();
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Content-Encoding: '.$charset);
header('Content-Type: '.$type.'; charset='.$charset);
header('Content-Disposition: attachment; filename="'.$file.'"');
header('Content-Length: '.$size);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
//header("Cache-Control: no-store, no-cache");
header("Pragma: no-cache");
// header('Pragma: public');
header('Expires: 0');
echo $content;
exit();
---
if ($download==true)
{
ob_clean();
header("Content-Description: File Transfer");
header('Content-type: application/zip');
header("Content-Length: " . filesize($filename));
header('Content-Disposition: attachment; filename="'.$zipFilename.'"');
header("Content-Transfer-Encoding: binary");
header("Pragma: no-cache");
header("Expires: 0");
echo file_get_contents($filename);
unlink($filename);
exit;
}
Zobrazeno 2 zpráv z 2.