I'm trying to move a file from one place to another place. In this case it is my user profile picture. Since I store my user profile picture base on their username, so when they change their username. I will need to move their profile photo, otherwise, the image link will be broken.
I've tried it here:
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);
}
I keep getting:
Any suggestions?
You're moving the file in the wrong direction.
It should be $move = File::move($old_path, $new_path);
... in other words, the first argument should be the OLD file location, the second argument should be the NEW file location... you have it backwards. :)
From the Laravel Docs
Move A File To A New Location
Storage::move('old/file1.jpg', 'new/file1.jpg');
Additionally, as said above, you shouldn't have the File::delete either since that file was moved and therefore deleted.
So, two things:
1) Switch the "old_path" and "new_path" and
2) Remove the File::delete line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With