Permission denied

Published 2 years ago by Khudadad

I trying to delete a file from public directory but I'm facing with this error:

ErrorException in BookController.php line 119: unlink(F:\Projects\kpucollege\public/): Permission denied

this is my function in the Controller.

public function destroy($id)
{
    $book = Book::findOrFail($id);
    $book_path = public_path().'/'.$book->book_path;
    unlink($book_path);
    $book->delete();
    return redirect('admin/dashboard/books')->with('message','کتاب موفقانه حذف شد');
}

Thanks

RomainLanz

The error is pretty clear...

You don't have the permission to delete the file. Also, note that there's nothing returned by $book->book_path.

JoeDawson

Yeah as @RomainLanz said, $book->book_path is returning null. It's trying to delete the /public folder.

Please sign in or create an account to participate in this conversation.