0

ここに私のコードがあります、

<?php
$file_name = "coupon.png";
$file_path = $_GET['path'];
$file_size = filesize($file_path);
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $file_size);
header('Content-Disposition: attachment; filename="' . $file_name . '";');
header('Content-Transfer-Encoding: binary');
readfile($file_path);
?>

$_GET['path']画像パス URL のPS

PC のブラウザでは、これらのコーディングがスムーズに実行できます。ただし、ユーザーがモバイル ブラウザーを使用してダウンロードすると、新しい Web ページ タブが表示されます。

ユーザーが画像をダウンロードしてモバイル ギャラリーに自動的に保存する方法はありますか?

4

1 に答える 1

0

このようにしてみてください:

<?php
$file_name = "coupon.png";
$file_path = $_GET['path'];
$file_size = filesize($file_path);
header('Pragma: public');
header('Expires: 0');
header('Last-Modified: ' . gmdate('D, d M Y H:i ') . ' GMT');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/force-download'); // Browser cant identifiy the type. so it will force to download
header('Content-Length: ' . $file_size);
header('Content-Disposition: attachment; filename="' . $file_name . '";');
header('Content-Transfer-Encoding: binary');
readfile($file_path);
?>

モバイル ブラウザはファイルを開く方法がわからないため、強制的にダウンロードされます。

于 2012-10-25T12:13:41.033 に答える