简体   繁体   English

如何显示来自PHPSECLIB的sftp-get的PDF返回

[英]How can I show a PDF return from sftp-get from PHPSECLIB

I want to show to the user a PDF or a PNG that is in my SFTP server. 我想向用户显示SFTP服务器中的PDF或PNG。 I am doing the connection with phpseclib to get the file. 我正在用phpseclib进行连接以获取文件。 How can I manipulate the file to show it in the browser? 如何处理文件以在浏览器中显示?

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

Send Content-Type and file content 发送内容类型和文件内容

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM