[英]How can I show a PDF return from sftp-get from PHPSECLIB
我想向用戶顯示SFTP服務器中的PDF或PNG。 我正在用phpseclib進行連接以獲取文件。 如何處理文件以在瀏覽器中顯示?
$key = new RSA();
$key->loadKey(file_get_contents('*******'));
$sftp = new SFTP($fsock);
if (!$sftp->login('*******', $key)) {
exit('Bad credentials!');
}
$path = "******";
$filename = $result[0]->filefinalname ;
$file = $sftp->get($path . $filename);
發送內容類型和文件內容
$file = '/path/to/temp/dir/'.uniqid(rand(), true); //temp name
file_put_contents($file,$sftp->get($path . $filename)); // save temp file
if (exif_imagetype($file)) //if this image
header("Content-Type: image/png"); //type file png
else
header("Content-type:application/pdf"); //type file pdf
header('Content-Length: ' . filesize($file)); //send size
readfile($file); //send file
unlink($file); //delete temp file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.