Home >Backend Development >PHP Problem >Detailed explanation of the chdir() function in PHP (with code examples)

Detailed explanation of the chdir() function in PHP (with code examples)

autoload
autoloadOriginal
2021-04-27 09:36:552260browse

    Detailed explanation of the chdir() function in PHP (with code examples)

    在php使用过程中,我们可能经常需要改变当前文件的目录,PHP中内置了这一方法,那就是chdir()函数,本文就带大家一起来看一看,如何利用chdir()改变当前文件的目录。

首先,我们来看一看chdir()函数的语法:

chdir    ( string $directory   )
  • $directory:需要更改成的路径

  • 返回值:bool类型的值,true表示更改成功,false表示更改失败,且抛出 E_WARNING 级别的错误。

代码实例:

<?php
 echo __DIR__."<br>";
 $directory="F:\learnlog\zend\php\upload\\";
//  echo $directory;
 echo "<br>";
//  echo getcwd();
//  chdir("upload");
chdir($directory);
echo getcwd();
?>
输出:F:\learnlog\zend\php

      F:\learnlog\zend\php\upload

推荐:2021年PHP面试题大汇总(收藏)》《php视频教程

The above is the detailed content of Detailed explanation of the chdir() function in PHP (with code examples). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn