0

ブラウザの新しいウィンドウから画像をダウンロードしたい。画像をクリックすると、新しいウィンドウに表示され、ダウンロードするボタンがあります。

今まで、新しいウィンドウで開くのではなく、シングルクリックでダウンロードすることができました。これは、ブラウザのポップアップが生成する画像をクリックして画像を開いたり保存したりすることを意味します。しかし、最初に新しいウィンドウで画像を開き、ダウンロードボタンをダウンロードしたいと思います。

これは私が使用している私のコードです。

<?php
if(isset($_GET['file'])){
    //Please give the Path like this
    $file = $_GET['file'];

    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;
    }
}
?>
4

0 に答える 0