私は初心者です。PHP と JavaScript に関する知識を深めようとしています。今回は何度も頭をぶつけて、答えを十分に探しました。
PDF を表示するためのプロキシ ページを作成しようとしています。できます!しかし、ファイルを保存したい場合、それ自体に「proxy.pdf」という名前が付けられます。私の Transformer Prime タブレットでは、代わりにスクリプト「proxy.php」をダウンロードします。
これは私のプロキシPHPコードがどのように見えるかです:
<?php
session_start;
// define path to image folder
$image_folder = realpath(dirname(__FILE__))."/imagefolder/";
// get image name from the query string
// no probe
if (isset($_GET['pic']) && basename($_GET['pic']) == $_GET['pic'])
{
$pic = $image_folder.$_GET['pic'];
if (file_exists($pic) && is_readable($pic))
{
// get the filename extension
$ext = substr($pic, -3);
// set the MIME type
switch ($ext)
{
case 'jpg':
$mime = 'image/jpeg';
break;
case 'gif':
$mime = 'image/gif';
break;
case 'png':
$mime = 'image/png';
break;
case 'pdf':
//alt octet-stream
$mime = 'application/pdf';
break;
default:
$mime = false;
}
// if a valid MIME type exists, display the image
// by sending appropriate headers and streaming the file
if ($mime)
{
header('Content-type: '.$mime);
header('Content-length: '.filesize($pic));
$file = fopen($pic, 'rb');
if ($file)
{
fpassthru($file);
exit;
}
}
}
}
?>