Reading / Using files in the server /home/ folder

六月ゝ 毕业季﹏ 提交于 2020-01-07 02:36:08

问题


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"); ?>

and

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

回答1:


This are two questions at once.

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

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 . How to access those image files from web?

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

Here comes an example for apache2

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

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" />


来源:https://stackoverflow.com/questions/14076613/reading-using-files-in-the-server-home-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!