Autor | Zpráva | ||
---|---|---|---|
kristoher Profil * |
#1 · Zasláno: 15. 1. 2011, 13:05:28
Jak se děla v PHP toto?
mám adresář s fotkami a chci nabídnout uživatelům "automatický odkaz pod fotkou" na který když se klikne tak se rovnou otevře windows okno pro uložení souboru... jde o png a jpg soubory... jak se to dělá? |
||
DJ Miky Profil |
#2 · Zasláno: 15. 1. 2011, 13:09:58
Aby prohlížeč nabídl uživateli stažení, je nutné poslat obrázek s jiným Content-Type než image/*, například se dává application/octet-stream nebo application/force-download.
V PHP změníš hlavičku funkcí header(), ale jde to vyřešit i na úrovni webserveru, např. pomocí .htaccess. |
||
denCo Profil |
#3 · Zasláno: 15. 1. 2011, 13:50:44 · Upravil/a: denCo
Raz som robil niečo podobné, tu je kód:
$file = "1.mp3"; // názov súboru $speed = 100; // rýchlosť sťahovania v kb/s if ( file_exists ( $file ) && is_file ( $file ) ) { header ('Content-Description: File Transfer'); header ('Content-Disposition: attachment; filename='.basename ( $file )); header ('Content-Transfer-Encoding: binary'); header ('Expires: 0'); header ('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header ('Pragma: public'); header ("Cache-control: private"); header ("Content-Type: application/octet-stream"); header ("Content-Length: ".filesize($file)); ob_clean (); flush (); $fd = fopen ( $file, "r" ); while ( !feof ( $fd ) ) { echo fread ( $fd, round ( $speed * 1024 ) ); flush (); sleep (1); } fclose ( $fd ); } dá sa tam nastaviť aj rýchlosť sťahovanie, čo je v tomto prípade asi jedno, tak sa to môže z tade vyhodiť $file = "1.mp3"; // názov súboru if ( file_exists ( $file ) && is_file ( $file ) ) { header ('Content-Description: File Transfer'); header ('Content-Disposition: attachment; filename='.basename ( $file )); header ('Content-Transfer-Encoding: binary'); header ('Expires: 0'); header ('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header ('Pragma: public'); header ("Cache-control: private"); header ("Content-Type: application/octet-stream"); header ("Content-Length: ".filesize($file)); readfile( $file ); } |
||
Časová prodleva: 11 let
|
0