2

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

kgbph
  • 841
  • 1
  • 8
  • 26
Victordb
  • 519
  • 1
  • 11
  • 25

1 Answers1

4

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.

Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
apokryfos
  • 38,771
  • 9
  • 70
  • 114