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
Release: 2023-03-09 12:24:01
Original
2263 people have browsed it

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

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

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

chdir    ( string $directory   )
Copy after login
  • $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();
?>
Copy after login
输出:F:\learnlog\zend\php

      F:\learnlog\zend\php\upload
Copy after login

推荐: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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template