读取/使用服务器/home/文件夹中的文件 [英] Reading / Using files in the server /home/ folder

查看:347
本文介绍了读取/使用服务器/home/文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有7个不同的自定义网站,都位于同一服务器上,它们使用相同的配置和图像文件.我想通过使用PHP包含"来引用这些文件,或者将它们作为src图像引用.不幸的是,当我尝试提取资源时,出现错误.有没有一种方法可以直接从/home/目录使用这些文件,以便在所有网站上都可以看到一个更改?这是我现在无法使用的东西:

I have 7 different custom websites, all on the same server, that use the same config and image files. I would like to reference those files by "including" using PHP, or referencing them as src images. Unfortunately, when I try to pull the resources, I get errors. Is there a way to use these files directly from the /home/ directory so that a single change there is seen on all websites? Here is what I am using now that isn't working:

 <?php include("/home/config.php"); ?>

<img style="vertical-align:bottom" src="/home/buy_button.png" border="0" />

推荐答案

这是两个问题.

1.如何使PHP包含这些文件. ?

1 . How can I make PHP include these files. ?

确保网络服务器用户例如ubuntu上的www数据具有访问这些文件的适当权限. 我会建议不同于/home/..(如果您问我的话)

Make sure the webserver user e.g. www-data on ubuntu has proper permissions to access those files. I would suggest something different from /home/.. (if you ask me)

2.如何从网络访问那些图像文件?

2 . How to access those image files from web?

如果您使用的是Apache,则必须创建一个别名,以使该图像可通过Web服务器访问.

If you are using apache you'll have to create an alias that makes that images accesible via the web server.

以下是apache2的示例

Here comes an example for apache2

Alias /img /home/path/to/images
<Directory "/home/path/to/images">
    Order allow,deny
    Allow from all
</Directory>

将此配置代码段放置在apache安装的正确位置,例如httpd.conf的末尾或一个单独的文件.不要忘记重启您的网络服务器.

Place this configuration snippet in the proper place of your apache installation e.g. end of httpd.conf or a separate file. Don't forget to restart your webserver.

现在,您应该可以访问以下图像了:

Now you should be able to access the images like:

<img style="vertical-align:bottom" src="http://www.myserver.com/img/buy_button.png"border="0" />

这篇关于读取/使用服务器/home/文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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