PHP path, how to call the path of your own server?

Source: Internet
Author: User
Keywords Php
I am now doing some experiments on my own, for example, to invoke my cousin's path, I ask how to use the path in a real project?

如果C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php调用C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php就得写:include('../../JiangSu/NanJing/NanJingEcho.php');

It's always easy to make a few mistakes. /"Every time I count this, I get so confused, how to write a simple point?"

I asked, and others told me to define the server with constants:

define('BASEPATH', 'C:\AppServ\www\YB-PHP\PathDemo\China\');include(BASEPATH . 'JiangSu/NanJing/NanJingEcho.php');

There seems to be a question of what permissions, I would like to ask, when the real project, how to use the parent path, cousin Path, the local path? To ensure that you change the server, the project can also be used?

Reply content:

I am now doing some experiments on my own, for example, to invoke my cousin's path, I ask how to use the path in a real project?

如果C:\AppServ\www\YB-PHP\PathDemo\China\ShanDong\LinYi\03.php调用C:\AppServ\www\YB-PHP\PathDemo\China\JiangSu\NanJing\NanJingEcho.php就得写:include('../../JiangSu/NanJing/NanJingEcho.php');

It's always easy to make a few mistakes. /"Every time I count this, I get so confused, how to write a simple point?"

I asked, and others told me to define the server with constants:

define('BASEPATH', 'C:\AppServ\www\YB-PHP\PathDemo\China\');include(BASEPATH . 'JiangSu/NanJing/NanJingEcho.php');

There seems to be a question of what permissions, I would like to ask, when the real project, how to use the parent path, cousin Path, the local path? To ensure that you change the server, the project can also be used?

Obviously 2 is a better solution, there is no permission problem you are considering: if there is a problem with permissions, then you use the. /.. /In the form of this problem will also occur .
Scenario 2 is also commonly used in a way that is actually more complex, such as:

defined('BASE_PATH') || define('BASE_PATH', __DIR__);defined('UPLOAD_BASE_URL') || define('UPLOAD_BASE_URL', '/uploads');defined('UPLOAD_PATH') || define('UPLOAD_PATH', BASE_PATH . UPLOAD_BASE_URL);//等等

When you refer to a file, you can see what is convenient, such as

require_once(BASE_PATH . '/app/functions.php');//或者require_once(__DIR__ . '/functions.php');

It's all OK.
To learn how to use __file__, __dir__, this is the best way to write the path directly, such as c:/workspace/project/app/functions.php, then what if the project is deployed to Linux?

So, take full account of the migration.

Hope to be helpful.

Cross-project invocation? is generally open an interface? Or two of projects need this data? Then open an API project alone.

Or is it a project where you want to invoke the database-driven class library? Then put this class library to find a Lib directory unified to include?

Generally this step by step to solve the problem, with the actual situation to analyze and solve the problem

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.