开发者

change file directory with php

How do I change the file l开发者_C百科ocation?

Now file is in "news" directory, how put file in "old_news"?


This is done by rename.

$success = rename("/news/file.txt", "/news_old/file.txt");

if ($success) 
 echo "Moved file!";
else
 echo "Failed to move file!";  


http://www.php.net/manual/en/function.rename.php

<?php
$cmd = 'mv "/home/user/me/dir1" "/mnt/shares/nfsmount/dir2"';
exec($cmd, $output, $return_val);

if ($return_val == 0) {
   echo "success";
} else {
   echo "failed";
}
?>


We're going to need more information about the problem. If you're trying to move the location of the PHP file, then just run:

mv file.php ../old_news/

If you're trying to change the working directory of the script, you can use the chdir function.

<?php
chdir("../new_directory/");

http://php.net/chdir

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜