mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Fixed delete old image on upload
This commit is contained in:
parent
db385b5f6b
commit
139c874308
|
@ -122,6 +122,13 @@ class ImageUploadRequest extends Request
|
||||||
// Remove Current image if exists
|
// Remove Current image if exists
|
||||||
if (($item->{$fieldname}) && (Storage::disk('public')->exists($path.'/'.$item->{$fieldname}))) {
|
if (($item->{$fieldname}) && (Storage::disk('public')->exists($path.'/'.$item->{$fieldname}))) {
|
||||||
\Log::debug('A file already exists that we are replacing - we should delete the old one.');
|
\Log::debug('A file already exists that we are replacing - we should delete the old one.');
|
||||||
|
|
||||||
|
// Assign the new filename as the fieldname
|
||||||
|
if (is_null($db_fieldname)) {
|
||||||
|
$item->{$fieldname} = $file_name;
|
||||||
|
} else {
|
||||||
|
$item->{$db_fieldname} = $file_name;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete($path.'/'.$item->{$fieldname});
|
Storage::disk('public')->delete($path.'/'.$item->{$fieldname});
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -130,29 +137,22 @@ class ImageUploadRequest extends Request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the new filename as the fieldname
|
|
||||||
if (is_null($db_fieldname)) {
|
|
||||||
$item->{$fieldname} = $file_name;
|
|
||||||
} else {
|
|
||||||
$item->{$db_fieldname} = $file_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user isn't uploading anything new but wants to delete their old image, do so
|
// If the user isn't uploading anything new but wants to delete their old image, do so
|
||||||
} else {
|
} else {
|
||||||
\Log::debug($item->{$fieldname});
|
|
||||||
\Log::debug('No image was passed - not sure what to do now.');
|
|
||||||
if ($this->input('image_delete')=='1') {
|
if ($this->input('image_delete')=='1') {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete($path . '/' . $item->{$fieldname});
|
|
||||||
|
|
||||||
if (is_null($db_fieldname)) {
|
if (is_null($db_fieldname)) {
|
||||||
$item->{$fieldname} = null;
|
$item->{$fieldname} = null;
|
||||||
|
Storage::disk('public')->delete($path . '/' . $item->{$fieldname});
|
||||||
} else {
|
} else {
|
||||||
$item->{$db_fieldname} = null;
|
$item->{$db_fieldname} = null;
|
||||||
|
Storage::disk('public')->delete($path . '/' . $item->{$fieldname});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
Loading…
Reference in a new issue