Reputation: 27
Im new in laravel ..1st im create some folders. and display all the folders..then Im trying to delete folder. when im select a folder and I want click delete button that selected folder deleted from main folder and database. my controller.php code is here
public function deletealbum($id)
{
$albums= ForumAlbum::find($id);
File::deleteDirectory('/img/Albums/', true);//delete image from temporary folder img/gallery
if (!is_null($albums))
{
$albums->delete(); //delete image from database
return Redirect::route('viewalbum')
->with('success',' Delete Album successfully');
}}
its working...but the problem is the folder name deleted only from database .not in main folder.how to delete folder inside a folder using laravel 4
Upvotes: 2
Views: 1701
Reputation: 1238
$data = FileUpload::FindOrFail($id); $fnm = $data['path'];
File::delete('upload/'.$fnm);
$data->delete();
Upvotes: 0
Reputation: 152860
I think the problem is the path you pass in. You should really use one of Laravels generators to get a full path to your folder. Assuming img
is a directory in public
you can do this:
File::deleteDirectory(public_path('img/Albums/' . $albums->albumname));
Assuming the name of the subdirectory is stored in $albums->albumname
Upvotes: 2