简体   繁体   中英

Laravel delete file in app folder (root)

How to delete files from Laravel app directory (not the public directory but the one in the root)?

I tried :

\Storage::Delete('App\file.php');
\Storage::Delete('\App\file.php');
\File::Delete('App\file.php');
\File::Delete('\App\file.php');
unlink ('\App\file.php');

Nothing works.

UPDATE: The file is in something like \\App\\folder\\folder\\file.db

When not specifying an absolute path then what is used is the current working directory (the value that getcwd() would return). Usually, that's the /public directory and not the actual project root.

You need to specific an absolute path using the Laravel helpers:

\File::delete(app_path('file.php'));

Note: You can't use the \\Storage helpers because they are limited to only work within the app storage folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM