dragonsun00000 2011-11-01 19:42
浏览 35
已采纳

如何正确链接文件?

From my previous experience, I've almost always had problems with linking files with my website projects.

For example, linking CSS styles, Javascript files and including files in PHP. The problem is, that on my PC, the directory of my project was /www/project-name/ and when I put the project on a server, the directory would be just /www/. When I uploaded the project to a server, images wouldn't show, styles wouldn't work, database connections wasn't set, functions were not defined etc...

So my question is: What is the best and most efficient way to link/include files?

Something that will work no matter what the directory of the project is, and possibly, if I include project/includes/mysql.class.php in file1.php, and I move that file to a different directory, it would still properly include project/includes/mysql.class.php

  • 写回答

4条回答 默认 最新

  • dongtan6695 2011-11-01 19:44
    关注

    You should use relative paths.

    Instead of specifying the full path ('/www/project-name/includes/whatever.php'), use a path relative to the current location:

    './includes/whatever.php'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?