Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 如何访问web应用程序外部目录中的图像_Apache_Image_Web Applications - Fatal编程技术网

Apache 如何访问web应用程序外部目录中的图像

Apache 如何访问web应用程序外部目录中的图像,apache,image,web-applications,Apache,Image,Web Applications,我正在使用Apache和Windows,我正在编写一个应用程序,它需要显示位于不同服务器上的部件的映像,而不是应用程序目录的路径。图像太多,无法移动,其他应用程序使用相同的图像 处理这个问题的最好办法是什么 后端是php和mysql——尽管我认为这与此无关 谢谢你看过符号链接了吗 ln -s LocalName FullPathOfRealFileLocation 既然图像在服务器上,为什么不在代码中直接引用它们呢 <img src="http://myotherserver.com/i

我正在使用Apache和Windows,我正在编写一个应用程序,它需要显示位于不同服务器上的部件的映像,而不是应用程序目录的路径。图像太多,无法移动,其他应用程序使用相同的图像

处理这个问题的最好办法是什么

后端是php和mysql——尽管我认为这与此无关


谢谢

你看过符号链接了吗

ln -s LocalName FullPathOfRealFileLocation

既然图像在服务器上,为什么不在代码中直接引用它们呢

<img src="http://myotherserver.com/images/picture.jpg"

如果您的文件存储在www根目录之外。
然后,您需要有足够的权限来访问这些文件

然后,你可以做如下事情:

<?php

$imageFileName = $_GET['image'];
$path = '/var/data/somewhere/';

$fullpath = $path . $imageFileName;

if (!is_file($fullpath))
{
   die('Image doesn't exist);
} else {
   $size = filesize($fullpath);
   $content = file_get_contents($fullpath);
   header("Content-type: image/jpeg");
   echo $content;
}

如果您使用Apache,我发现这是最好的答案。我就是,使用Apache别名特性,允许访问内部目录

如上面BGY的回答所示

我在http.conf中添加了以下内容:

Alias /fabimages p:/IMDATA/IMAGES
<Directory p:/IMDATA/IMAGES>
    Order allow,deny
    Allow from all
</Directory> 

是的,我试过了。这在任何unix/linux变体中都能很好地工作。不能在路径名中间使用窗口快捷方式。ie images/shortcutToAnotherFolder/image.jpg在windows中不工作。谢谢您的建议。另一台服务器无法通过internet访问,它位于记帐服务器上。我忘了提到一个要点,那就是我需要从Javascript访问目录。
var fabimage = document.getElementById("fabImageTag");
fabimage.src="/fabimages/"+imageName; // and it picks up the image from p:/IMDATA/IMAGES