Как я могу показать PDF возврат от sftp-get от PHPSECLIB - PullRequest
0 голосов
/ 14 февраля 2019

Я хочу показать пользователю PDF или PNG, который находится на моем SFTP-сервере.Я делаю соединение с 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); 

1 Ответ

0 голосов
/ 14 февраля 2019

Отправка содержимого-Тип и содержимое файла

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