1
$data = Student::find($id);
$filePath = $data['photo'];
unlink($filePath);

$filepath hold a value like this - storage/other-document/images-1/jj.png ,because am storing the file jj.png inside the folder images-1. images-1 is a custom created folder. The unlink function here deletes the file from this images-1folder . but i want the images-1 folder also to get deleted along with this. Is it possible? How to do that?

1 Answers1

0

You can look at some recursive way to do it : How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?

Or in your case, simply get the path of the folder after unlink the file :

$filePath = $data['photo'];
unlink($filePath);
$folder = dirname($filePath);
rmdir($folder);
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84