PHP를 사용하여 별도의 디렉토리에있는 파일의 이름을 바꾸려고합니다. 이것이 제가 시도한 것입니다.파일이 스크립트와 다른 디렉토리에있을 때 PHP에서 파일의 이름을 바꾸려면 어떻게합니까?
<?php
//file i want to change
$file_dir = '/home/name/here/myfile.txt';
//directory of script
$cur_dir = '/home/name/there/myhandler.php';
//change directory to location of file to be renamed
chdir('/home/name/here/');
//change file name
rename($file_dir, 'newfilename.txt');
?>
그러나 이전 디렉토리에서 여전히 파일을 찾는 중 오류가 발생합니다.
rename($file_dir, newfilename.txt): No such file or directory in /home/name/there/myhandler.php
이 코드는 'rename ('full/file/path/name.txt ','newname.txt ')이라는 코드가있는 모든 예제에서 작동했습니다. –