1

コードを使用して、実際のパスを表示せずに画像を印刷しています。しかし、その画像をコンピュータに保存したい場合、画像の名前として常にPHPファイル名が表示されるため、問題が発生します。

$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);

phpファイルはppupload.phpであり、ダイアログボックスに画像(たとえばPNG画像)を保存したい場合は、ファイル名(ppupload.php.png)を表示し、それを画像そのものにします。

次のようにデータベースに保存された画像パス:folder/folder/filename.ext

4

2 に答える 2

2

Content Dispositionヘッダーを設定してみましたか?

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

これは役立つかもしれません。

于 2012-05-03T15:26:16.897 に答える
1

このheader( "Content-Disposition:inline; filename = \" myimg.png \ "");のようなものを追加してみてください。

于 2012-05-03T15:25:55.413 に答える