In questo tutorial PHP imparerete come creare una funzione che forza il download di un’immagine.
Per fare quanto detto, avremo bisogno di utilizzare gli headers che ci permetteranno di interagire con il browser del client.
function forceImageDownload($image_path) {
//impostiamo il nome del file
$filename = basename($image_path);
//intestazioni
header("Content-Transfer-Encoding: binary");
header("Content-Type: image/jpg");
header("Content-Disposition: attachment; filename=$filename");
readfile($path_to_image);
}
fonte: www.sastgroup.com






