How to transfer file to php Laravel 5?

I am trying to move a file from one place to another. In this case, my user profile picture. Since I store the user profile database on my own username, therefore, when they change them username. I will need to move the photo of my profile, otherwise the link to the image will be broken.

I tried here 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 kept getting

enter image description here

Any suggestions for me?

+4
source share
2 answers

You are 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 location of the OLD file, the second argument should be the location of the NEW file ... you have this in reverse order. :)

From Laravel Docs

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

, , File:: delete .

, :

1) "old_path" "new_path"

2) File:: delete

+7

, . .

0

All Articles