Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将文件从一个位置移动到另一个位置?_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 如何将文件从一个位置移动到另一个位置?

Php 如何将文件从一个位置移动到另一个位置?,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在尝试将文件从一个地方移动到另一个地方。在本例中,它是我的用户配置文件图片。因为我根据他们的用户名存储我的用户配置文件图片,所以当他们更改用户名时。我将需要移动他们的个人资料照片,否则,图像链接将被破坏 我在这里试过: if ( $user->username != Input::get('username')) { $new_path = public_path().'/img/logo/'. Input::get('username').'/'.$user->logo

我正在尝试将文件从一个地方移动到另一个地方。在本例中,它是我的用户配置文件图片。因为我根据他们的用户名存储我的用户配置文件图片,所以当他们更改用户名时。我将需要移动他们的个人资料照片,否则,图像链接将被破坏

我在这里试过:

if ( $user->username != Input::get('username')) {
    $new_path = public_path().'/img/logo/'. Input::get('username').'/'.$user->logo_path;
    $old_path = public_path().'/img/logo/'. $user->username.'/'.$user->logo_path;
    $move = File::move($new_path, $old_path);
    $delete = File::delete($old_path);
}

我不断得到:


有什么建议吗

您将文件移动到错误的方向

它应该是
$move=File::move($old\u path,$new\u path)

。。。换句话说,第一个参数应该是旧文件位置,第二个参数应该是新文件位置。。。你把它倒过来了。:)

将文件移动到新位置

存储:move('old/file1.jpg','new/file1.jpg')

此外,如上所述,您也不应该让File::delete,因为该文件已被移动并因此被删除

因此,有两件事:

1) 切换“旧路径”和“新路径”,然后


2) 删除文件::删除行

我建议您根据用户ID而不是用户名存储文件,这样您就不必在用户名更改时移动任何内容。仅替换现有文件。

目录是否存在?如果没有,就先创建它。
delete
是没有意义的。首先,移动文件将从其原始位置删除该文件。