Remember me - Lost password?
merlinox : about 1 year ago
#php Avrei bisogno di una funzione che:
- dato un path di un file in formato url (http://..)
- mi buttasse fuori lo stesso file, come attachment settando il content type
- per il tipo file e il content-type non ho problemi, è uno unico

Io ho trovato vari modi per farlo, ma tutti con i file remoti, mi restituiscono un file corrotto.

Grazie.
from Rovigo in php - 22 replies
contezero74
embed : about 1 year ago
non ho capito
from here - detail
merlinox : about 1 year ago
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename="x.jpg"');
???
from Rovigo - detail
capobecchino : about 1 year ago
solo con queste 2 righe non ci facciamo niente, posta tutto il codice che utilizzi
from Sesto San Giovanni, IT - detail
merlinox : about 1 year ago
manca l'ultima riga, ovvero quella che prende il file da una url e lo "pubblica".
from Rovigo - detail
capobecchino : about 1 year ago
come lo prendi il file e lo pubblichi?
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
il file lo prendo da una URL, ad esempio http://meemi.com/a/m/e/r/l/i/n...
from Rovigo - detail
capobecchino : about 1 year ago
si l'istruzione che usi qual'è?
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
ma dio santissimo, se sono qui a chiedervi cosa usare, come faccio a dirvelo?
from Rovigo - detail
capobecchino : about 1 year ago
ahh! tu vuoi sapere cosa devi usare dopo quelle 2 .. semplice readfile(file);
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
ma readfile non funziona solo con un path "fisico"?
from Rovigo - detail
capobecchino : about 1 year ago
no no
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
quindi è sufficiente sparare i due head, più il readfile? così?
<?php
$file = 'http://meemi.com/a/m/e/r/l/i/n...;

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
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('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
from Rovigo - detail
capobecchino : about 1 year ago
yes
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
mmm ovviamente hai già provato te uno script simile? Io qui non ho server al volo dove provarlo.
from Rovigo - detail
capobecchino : about 1 year ago
si non usavo tutti quegli header ma si l'ho provato ... ma se mi spieghi meglio a cosa ti serve magari si trova una soluzione migliore
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
@capobecchino ma hai messo i freni? non ho molto da spiegare. ho una pagina del cazzo tipo download.php?idfile=100

e voglio che vada a pigliarsi la URL di quel file dal database (o da dove vuole) e mi spari fuori il file con il nome indicato nel "header" mascherando di fatto la sua url (http://...)
from Rovigo - detail
capobecchino : about 1 year ago
ookkk allora stai a posto
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
hai possibilità di fare un test al volo per caso?
from Rovigo - detail
capobecchino : about 1 year ago
si ora te lo faccio
from Cinisello Balsamo, IT - detail
capobecchino : about 1 year ago
leva il if (file_exists($file)) che non ti serve a nulla su file esterni e tutto funziona alla perfezione, test fatto correttamente
from Cinisello Balsamo, IT - detail
merlinox : about 1 year ago
grandioso. grazie.
from Rovigo - detail
capobecchino : about 1 year ago
de nada guagliò
from Cinisello Balsamo, IT - detail
New to meemi?
Join now to quickly and easily way

Problem? Rigenerate new code
By clicking the button, you agree all terms of service