【问题标题】:Can I programmatically change the path to the file using PHP?我可以使用 PHP 以编程方式更改文件的路径吗?
【发布时间】:2017-11-22 22:21:37
【问题描述】:

我可以使用 PHP 以编程方式更改文件的路径吗?

例如,将D:\ISO & SOFT\test.txt 更改为D:\test.txt

【问题讨论】:

  • 您可以在 exec 命令( exec("cd Scripts && ./script.sh") )中更改目录,或者使用 chdir 更改 PHP 进程的工作目录()。
  • 您想将文件 [test.txt] 从 D:\ISO & SOFT\ 移动到 D:/ 吗?
  • 如果您想移动文件,那么您的问题是重复的。这个问题已经被问过here。 @PrabhuNandanKumar 的当前答案也从那里被盗。 :P

标签: php file path filepath


【解决方案1】:

为此,您可以简单地将文件从当前路径移动到所需路径。

使用以下步骤在 PHP 中移动文件:

$uploads_dir = '/uploads'; // Desired path
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "$uploads_dir/$name"); //Moving file at desire path
    }
}

【讨论】:

    猜你喜欢
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-06
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多