guardar una imagen del problema del navegador

I'm using code to print an image without showing the real path for it. But I have a problem when I want to save that image to my computer because its always show the PHP file name as the name for the image.

$id = intval($_REQUEST["id"]);
$getimage = $db->query("select id,img from bbup where id='$id'");
$fetch_image = $db->fetch($getimage);
$filename = $fetch_image['img'];
if (!$id) {
    echo "Wrong Id";
    exit;
}
if (!file_exists($filename)) {
    echo "Image not found.";
    exit;
}
$aaa = SITE_URL . $filename;
$imginfo = getimagesize($aaa);
header("Content-type: " . $imginfo['mime']);
readfile($aaa);

El archivo php es ppupload.php and when I want to save the image (let's say it is a PNG image) in the dialog box the name of the file show ( ppupload.php.png ) and I want it to be the image itself.

The image path stored into the database like this: folder/folder/filename.ext.

preguntado el 03 de mayo de 12 a las 16:05

2 Respuestas

Have you tried setting the Content Disposition header?

header('Content-Disposition: attachment; filename='.$filename);
header('Content-Type: application/octet-stream');

Esto podría ayudar.

contestado el 03 de mayo de 12 a las 16:05

the file first is showing the the browser dear but , the problem when i want to save it to my computer - Camino Bb

You can try to add something like this header("Content-Disposition: inline; filename=\"myimg.png\"");

contestado el 03 de mayo de 12 a las 16:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.