不能使用apache查看本地映像?

时间:2022-09-17 08:01:01

I'm on mac osx10.6.8. I'm using XAMPP. I'm running all my script through firefox by typing in localhost/index.php etc. All the scripts run, and everything I've written so far works fine.

我在mac osx10.6.8。我使用XAMPP。我通过输入localhost/索引来运行我所有的脚本。php等等,所有的脚本都运行,我写的所有东西都没问题。

Right now, I'm able to browse my folders and upload images. It will successfully save and rename an image and store it in my htdocs folder. The problem is when I try to display the image that was just saved.

现在,我可以浏览我的文件夹和上传图片。它将成功地保存并重命名一个映像并将其存储在我的htdocs文件夹中。问题是当我试图显示刚刚保存的图像时。

I have the following code:

我有以下代码:

<img src="file:///applications/XAMPP/xamppfiles/htdocs/Images/1921304523pvyNZ.jpg">

If I type in file:///applications/XAMPP/xamppfiles/htdocs/Images/1921304523pvyNZ.jpg in the address bar, the picture comes up. But when I try to use img src, just a broken image shows up. When I click on get info for that broken image, it gives me the exact address and even displays the image in "media preview." Why, then won't it display it in the website?

如果我输入文件:///应用程序/XAMPP/xamppfiles/htdocs/Images/1921304523pvyNZ.jpg在地址栏,图片就会出现。但是当我尝试使用img src时,只有一个坏的图像出现了。当我点击获取那个破碎图像的信息时,它会给我准确的地址,甚至在“媒体预览”中显示图像。为什么,那么它不会在网站上显示吗?

2 个解决方案

#1


4  

Instead of file://, use http://localhost/path/to/image/ .. then the images will be served through xampp rather than from the filesystem. I expect this is a security feature of your browser, not to mix filesystem and http-served content.

而不是file://,使用http://localhost/path/to/image/ ..然后,将通过xampp而不是从文件系统提供图像。我希望这是您浏览器的安全特性,而不是混合文件系统和http服务内容。

In your case, you probably want http://localhost/Images/1921304523pvyNZ.jpg

在您的示例中,您可能需要http://localhost/Images/1921304523pvyNZ.jpg。

Also, make sure 'Images' does indeed have an upper case 'I'. No big deal on OSX but will be if you deploy on a Linux/UNIX server.

另外,确保“图像”确实有一个大写的“I”。如果您在Linux/UNIX服务器上部署,那么OSX上没什么大不了的。

As Fabricio points out, you can/should reference the images relatively, and keep your web application easy to deploy. So if you are displaying http://localhost/index.php, the image path is just Images/xxxx.jpg.

正如Fabricio指出的那样,您可以/应该相对地引用这些映像,并使您的web应用程序易于部署。因此,如果您正在显示http://localhost/index。php,图像路径就是图像/xxxx.jpg。

#2


0  

I had a similar issue. I found the problem by looking at my Xampp error log. For some reason my images file permissions were very limited. -rx------... I just changed the file permission to allow all users to be able to read those files. Just a note in my opinion since I am lazy, others will probably disagree, you can give them full permission if it is on your own computer, i.e. 777. But in best practice you should only give the files the permissions that are needed for security reasons...

我有一个类似的问题。通过查看Xampp错误日志,我发现了这个问题。由于某些原因,我的图像文件权限非常有限。rx - - - - - -…我只是更改了文件权限,允许所有用户都能够读取这些文件。因为我很懒,别人可能不同意我的看法,如果是在你自己的电脑上,你可以给他们完全的许可,也就是777。但是在最佳实践中,您应该仅为安全原因提供所需的权限……

Since you are using a Mac you can use the chmod command to do this in terminal.
go to the file directory in terminal. cd /Applications/XAMP/xamppfiles/htdocs/.../images/

由于您使用的是Mac,所以您可以使用chmod命令在终端执行此操作。转到终端的文件目录。cd /应用程序/ XAMP / xamppfiles /根/…/图片/

then type in chmod 644 yourfilename.extension

然后输入chmod 644 yourfilename.extension。

you can confirm that is was changed by using ls -l

您可以使用ls -l来确认是否更改了。

644 should give you -rw-r--r-- This should be pretty secure.

644应该给你-rw-r- r-这应该很安全。

#1


4  

Instead of file://, use http://localhost/path/to/image/ .. then the images will be served through xampp rather than from the filesystem. I expect this is a security feature of your browser, not to mix filesystem and http-served content.

而不是file://,使用http://localhost/path/to/image/ ..然后,将通过xampp而不是从文件系统提供图像。我希望这是您浏览器的安全特性,而不是混合文件系统和http服务内容。

In your case, you probably want http://localhost/Images/1921304523pvyNZ.jpg

在您的示例中,您可能需要http://localhost/Images/1921304523pvyNZ.jpg。

Also, make sure 'Images' does indeed have an upper case 'I'. No big deal on OSX but will be if you deploy on a Linux/UNIX server.

另外,确保“图像”确实有一个大写的“I”。如果您在Linux/UNIX服务器上部署,那么OSX上没什么大不了的。

As Fabricio points out, you can/should reference the images relatively, and keep your web application easy to deploy. So if you are displaying http://localhost/index.php, the image path is just Images/xxxx.jpg.

正如Fabricio指出的那样,您可以/应该相对地引用这些映像,并使您的web应用程序易于部署。因此,如果您正在显示http://localhost/index。php,图像路径就是图像/xxxx.jpg。

#2


0  

I had a similar issue. I found the problem by looking at my Xampp error log. For some reason my images file permissions were very limited. -rx------... I just changed the file permission to allow all users to be able to read those files. Just a note in my opinion since I am lazy, others will probably disagree, you can give them full permission if it is on your own computer, i.e. 777. But in best practice you should only give the files the permissions that are needed for security reasons...

我有一个类似的问题。通过查看Xampp错误日志,我发现了这个问题。由于某些原因,我的图像文件权限非常有限。rx - - - - - -…我只是更改了文件权限,允许所有用户都能够读取这些文件。因为我很懒,别人可能不同意我的看法,如果是在你自己的电脑上,你可以给他们完全的许可,也就是777。但是在最佳实践中,您应该仅为安全原因提供所需的权限……

Since you are using a Mac you can use the chmod command to do this in terminal.
go to the file directory in terminal. cd /Applications/XAMP/xamppfiles/htdocs/.../images/

由于您使用的是Mac,所以您可以使用chmod命令在终端执行此操作。转到终端的文件目录。cd /应用程序/ XAMP / xamppfiles /根/…/图片/

then type in chmod 644 yourfilename.extension

然后输入chmod 644 yourfilename.extension。

you can confirm that is was changed by using ls -l

您可以使用ls -l来确认是否更改了。

644 should give you -rw-r--r-- This should be pretty secure.

644应该给你-rw-r- r-这应该很安全。