Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-08-23 14:05:09 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
40b629d35d3f09fd66226a0e62999ef587b95d5f
40b629d3
1 parent
958ed627
Fixed image folder deletion. Fixes #22.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
6 deletions
app/Http/Controllers/ImageController.php
app/Http/routes.php
app/Http/Controllers/ImageController.php
View file @
40b629d
...
...
@@ -177,14 +177,30 @@ class ImageController extends Controller
// Delete files
$folder
=
public_path
()
.
dirname
(
$image
->
url
);
$pattern
=
'/'
.
preg_quote
(
basename
(
$image
->
url
))
.
'/'
;
$dir
=
new
RecursiveDirectoryIterator
(
$folder
);
$ite
=
new
RecursiveIteratorIterator
(
$dir
);
$files
=
new
RegexIterator
(
$ite
,
$pattern
,
RegexIterator
::
ALL_MATCHES
);
foreach
(
$files
as
$path
=>
$file
)
{
unlink
(
$path
);
$fileName
=
basename
(
$image
->
url
);
// Delete thumbnails
foreach
(
glob
(
$folder
.
'/*'
)
as
$file
)
{
if
(
is_dir
(
$file
))
{
$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
();
// Delete parent folder if empty
if
(
count
(
glob
(
$folder
.
'/*'
))
===
0
)
{
rmdir
(
$folder
);
}
return
response
()
->
json
(
'Image Deleted'
);
}
...
...
app/Http/routes.php
View file @
40b629d
...
...
@@ -70,6 +70,7 @@ Route::group(['middleware' => 'auth'], function() {
Route
::
get
(
'/images/all'
,
'ImageController@getAll'
);
Route
::
put
(
'/images/update/{imageId}'
,
'ImageController@update'
);
Route
::
delete
(
'/images/{imageId}'
,
'ImageController@destroy'
);
Route
::
get
(
'/images/{imageId}/delete'
,
'ImageController@destroy'
);
Route
::
get
(
'/images/all/{page}'
,
'ImageController@getAll'
);
Route
::
get
(
'/images/{any}'
,
'ImageController@getImage'
)
->
where
(
'any'
,
'.*'
);
...
...
Please
register
or
sign in
to post a comment