PHP Gets the directory where the current file is located getcwd () function usage

Source: Internet
Author: User
The GETCHWD () function returns the current working directory. This function returns the current working directory if it succeeds. The failure returns FALSE.

GETCHWD () Function code instance

<?php Echo getcwd (). "<br/>"; echo dirname (FILE);?>

PHP can use the magic constant file to get the absolute path of the current files, regardless of whether the current file is contained by other files, which is very useful in many cases, but sometimes when we read and write files and other operations, relative to the current script working directory, that is, the directory of the portal PHP files, Another function getcwd () provided by PHP can now be used to get

Compare the differences between the two:

<?php if (!defined (' BasePath ')) exit (' No Direct script access allowed ');  Include APPPATH. ' libraries/api/base.api.php ';  Include APPPATH. ' libraries/api/organ.api.php ';  Include APPPATH. ' libraries/api/task.api.php ';  Include APPPATH. ' libraries/api/pay.api.php ';    Class Notice extends my_controller{public      $coid = 0;        Public Function Index () {          echo getcwd ();          Echo ' <br> ';          echo FILE;      }  }

The results of the operation contrast, the difference is at a glance:

/data/html/test.oa/public/data/html/test.oa/application/controllers/notice.php

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.