路径,使用Apache与Windows映像 [英] Paths for images using Apache with Windows

查看:105
本文介绍了路径,使用Apache与Windows映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在本地使用Apache与Windows连接测试的一个问题。最后的链接的格式如下:

I have a problem with links testing locally using Apache with Windows. The final links have the following format:

file:///C:/Documents and Settings/USUARIO/My Documents/xampp/htdocs/my_website/images/january/my_image.jpg

图像不显示。但是,如果我直接从SRC img标签复制并粘贴到浏览器(Firefox),图像显示出来。

The images do not show. However, if I directly copy the src from the img tag and paste it into the browser (Firefox), the image shows up.

我生成使用下面的code链接:

我使用定义的图像目录:(IMAGE_DIR,目录名(__ __ FILE)/图片/')定义; 结果
然后我用下面的格式化路径:

I define the images directory using: define(IMAGE_DIR, dirname(__FILE__).'/images/');
Then I use the following to format the path:

$imgPath = IMAGE_DIR.$month.$img;   
if($localServer)
{
   $imgPath = str_replace('/','\\', $imgPath);
   $imgPath = 'file:///'.$imgPath;
}

我我做错了什么?

What I'm I doing wrong?

推荐答案

您正在生成使用文件的图像源:// 的URL在一个从加载的页面网络服务器。文件URL指示浏览器直接从磁盘加载一个文件,而无需对Web服务器的请求。出于安全原因,Firefox和其他浏览器不允许由Web服务器提供引用本地文件的网页,所以不显示图像。人远程访问你的网站将无法访问文件或者是因为图像源将是他们的计算机上的路径参考。

You are generating image sources that use file:// URLs in a page that was loaded from a web server. File URLs instruct the browser to load a file directly from the disk without making a request to the web server. For security reasons, Firefox and other browsers don't allow pages served by a web server to reference local files, so don't show the images. People accessing your site remotely won't be able to access the files either because the image source would be a reference to a path on their computer.

要获得的图像出现,你需要改变你的图像源指的位置在Web服务器上,例如图像/月/ my_image.jpg /images/january/my_image.jpg

To get the images to appear, you'll need to change your image sources to refer to locations on a web server, for example images/january/my_image.jpg or /images/january/my_image.jpg.

图像/月/ my_image.jpg 将是相对于页面的Web浏览器PTED间$ P $所请求。例如,如果图像在页面上出现在 HTTP://localhost/page1.php ,那么浏览器就会要求的http://本地主机/images/january/my_image.jpg 。但是,如果像在 HTTP使用的页面上://本地主机/ 子目录 /page1.php 时,浏览器会要求的http://本地主机/ 子目录 /images/january/my_image.jpg 而不是

images/january/my_image.jpg will be interpreted by the web browser relative to the page being requested. For example, if the image appears on the page at http://localhost/page1.php, then the browser will request http://localhost/images/january/my_image.jpg. However, if the image is used on a page at http://localhost/subdir/page1.php, the browser will request http://localhost/subdir/images/january/my_image.jpg instead.

/ 图片/月/ my_image.jpg 将永远是间$ P $相对于网站的根PTED。 Web浏览器将要求 HTTP://localhost/images/january/my_image.jpg 有关 HTTP的任何页面://本地主机

/images/january/my_image.jpg will always be interpreted relative to the root of the website. The web browser will request http://localhost/images/january/my_image.jpg for any page on http://localhost.

您还可以,如果你需要参考图像另一台Web服务器上,例如, HTTP使用绝对URL C>。

You can also use an absolute URL if you need to refer to an image on another web server, for example, http://otherhost/images/january/my_image.jpg.

这篇关于路径,使用Apache与Windows映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆