mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Fixed image folder deletion. Fixes #22.
This commit is contained in:
parent
958ed627dd
commit
40b629d35d
@ -177,14 +177,30 @@ class ImageController extends Controller
|
|||||||
|
|
||||||
// Delete files
|
// Delete files
|
||||||
$folder = public_path() . dirname($image->url);
|
$folder = public_path() . dirname($image->url);
|
||||||
$pattern = '/' . preg_quote(basename($image->url)). '/';
|
$fileName = basename($image->url);
|
||||||
$dir = new RecursiveDirectoryIterator($folder);
|
|
||||||
$ite = new RecursiveIteratorIterator($dir);
|
// Delete thumbnails
|
||||||
$files = new RegexIterator($ite, $pattern, RegexIterator::ALL_MATCHES);
|
foreach(glob($folder . '/*') as $file) {
|
||||||
foreach($files as $path => $file) {
|
if(is_dir($file)) {
|
||||||
unlink($path);
|
$thumbName = $file . '/' . $fileName;
|
||||||
|
if(file_exists($file)) {
|
||||||
|
unlink($thumbName);
|
||||||
|
}
|
||||||
|
// Remove thumb folder if empty
|
||||||
|
if(count(glob($file . '/*')) === 0) {
|
||||||
|
rmdir($file);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete file and database entry
|
||||||
|
unlink($folder . '/' . $fileName);
|
||||||
$image->delete();
|
$image->delete();
|
||||||
|
|
||||||
|
// Delete parent folder if empty
|
||||||
|
if(count(glob($folder . '/*')) === 0) {
|
||||||
|
rmdir($folder);
|
||||||
|
}
|
||||||
return response()->json('Image Deleted');
|
return response()->json('Image Deleted');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ Route::group(['middleware' => 'auth'], function() {
|
|||||||
Route::get('/images/all', 'ImageController@getAll');
|
Route::get('/images/all', 'ImageController@getAll');
|
||||||
Route::put('/images/update/{imageId}', 'ImageController@update');
|
Route::put('/images/update/{imageId}', 'ImageController@update');
|
||||||
Route::delete('/images/{imageId}', 'ImageController@destroy');
|
Route::delete('/images/{imageId}', 'ImageController@destroy');
|
||||||
|
Route::get('/images/{imageId}/delete', 'ImageController@destroy');
|
||||||
Route::get('/images/all/{page}', 'ImageController@getAll');
|
Route::get('/images/all/{page}', 'ImageController@getAll');
|
||||||
Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
|
Route::get('/images/{any}', 'ImageController@getImage')->where('any', '.*');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user