0

I am currently hosting a php script on a public web server that I use to retrieve an image for me hosted locally on the same server. I was recently told I would need to do the same thing for another process, except our new process will need to pull images from a Windows server. Could anyone recommend the best way to go about doing this? I have tried just utilizing a direct path such as the following with no luck:

<?
  $im = file_get_contents('\\SERVER-NAME\Photos\image.jpg');
  header('content-type: image/gif');
  echo $im;
?>

Any insight would be greatly appreciated. Thanks in advance for any assistance!

4

1 回答 1

1

您可以使用imagecreatefromstring http://php.net/manual/en/function.imagecreatefromstring.php

$data = file_get_contents('\\SERVER-NAME\Photos\image.jpg');
$im = imagecreatefromstring($data);

if ($im !== false) {
    header('Content-Type: image/gif');
    imagepng($im);
    imagedestroy($im);
}

让我知道是否产生任何错误..以便我可以进一步帮助您...

编辑 1

一个。Warning: file_get_contents(\WINDOWS-SERVERNAME\Photos\image.jpg) [function.file-get-contents]:

UNC paths如果允许 Apache 用户访问网络文件夹,我可以看到您正在尝试访问这将起作用

B.Fatal error: Call to undefined function imagecreatefromstring() in

这意味着您的 PHP 服务器上没有安装 GD http://php.net/manual/en/book.image.php,因为这是您的 linux 机器,您可以运行类似# yum install php53u-gd

于 2012-04-24T16:42:09.507 回答