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
Image 图像路径不工作_Image_Zend Framework - Fatal编程技术网

Image 图像路径不工作

Image 图像路径不工作,image,zend-framework,Image,Zend Framework,我正在使用Zend,我的/public中有一个名为/profile/的文件夹。我将个人资料图片存储在其中。假设这里面有一个名为/test.png的文件。我尝试使用 <?php $path = APPLICATION_PATH . '/../public/profile/test.png'; echo '<img src="' . $path . '" />'; ?> 但是,没有任何负载!我复制代码并将其粘贴到URL中,这样可以很好地显示图像!我做错了什么 谢谢,应用

我正在使用Zend,我的
/public
中有一个名为
/profile/
的文件夹。我将个人资料图片存储在其中。假设这里面有一个名为
/test.png
的文件。我尝试使用

<?php
$path = APPLICATION_PATH . '/../public/profile/test.png';
echo '<img src="' . $path . '" />';
?>

但是,没有任何负载!我复制代码并将其粘贴到URL中,这样可以很好地显示图像!我做错了什么


谢谢,应用程序路径不是HTTP,而是本地文件系统路径。您想要的是URL而不是路径

$url = $_SERVER['HTTP_HOST'] . '/profile/test.png';

echo sprintf('<img alt="" src="%s" />', $url);
$url=$\u服务器['HTTP\u主机].'/profile/test.png';
echo sprintf(“”,$url);

实际上要简单得多:

你总是需要一个vhost来完成这项工作。它通常指向文件夹

your-application/public
如果您的图像位于:

your-application/public/profile/test.png
然后指定图像路径:

<img src="/profile/test.png" />


在这种情况下,不需要使用PHP。

谢谢!我不知道为什么我没有想到这个!如果我还想用这条路怎么办?我想将图像存储在/data/文件夹而不是公用文件夹中。因为您的vhost指向/public,所以浏览器只能访问该目录下的文件。除非您创建另一个vhost,否则无法访问任何其他目录、父目录和其他目录。