1

I work with Laravel 5.3. I have created file.txt in public directory and want to move it. In tinker console I execute commands:

>>> $path = public_path() . '/file.txt';
=> "/home/jan/fun/tad/public/file.txt"
>>> $newPath = public_path() . '/new_folder/file.txt';
=> "/home/jan/fun/tad/public/new_folder/file.txt"
>>> Storage::move($path, $newPath);
League\Flysystem\FileNotFoundException with message 'File not found at path: home/jan/fun/tad/public/file.txt'

I have tried different combinations, none worked.

How should I construct correct path?

janjanjan
  • 57
  • 10
  • 1
    It didn't work because file was not found ;) – lchachurski Oct 25 '17 at 15:22
  • You have hit the nail on the head. – janjanjan Oct 25 '17 at 15:33
  • 1
    By default, the public disk uses the local driver and stores these files in folder **storage/app/public** not your **public** folder.. Take a look at [The Public Disk](https://laravel.com/docs/5.5/filesystem#the-public-disk) – ljubadr Oct 25 '17 at 15:36
  • You can use * if (file_exists($filename)) { * –  Oct 25 '17 at 15:38
  • 1
    Can you try using `rename($path, $newPath);` ? – Cédric Oct 25 '17 at 15:38
  • @Cedroux this have worked. That's weird, because `Storage::move()` is just an wrapper around php's `rename()` – janjanjan Oct 25 '17 at 15:45
  • 1
    @janjanjan `Storage` expects paths that are **relative** to **'default'** driver that is set in **config/filesystems.php**. And if if you didn't change anything it's set to `storage_path('app/public')`, which is **storage/app/public**. If you want to use `Storage` with just **public/** folder, look at [this answer](https://stackoverflow.com/a/46799674/3226121), part where it says **Another approach would be to create new disk...* – ljubadr Oct 25 '17 at 15:54

0 Answers0