fix: Moved uploaded files to the storage folder
This commit is contained in:
parent
51214f7262
commit
fa571ada9a
4 changed files with 93 additions and 57 deletions
|
|
@ -78,15 +78,21 @@ class ArticlesController extends Controller
|
|||
$status = 0;
|
||||
|
||||
$imageName = Str::slug($title) . '-jeusselin-' . date('d-m-Y') . '.' . $picture->extension();
|
||||
$picture->move(public_path('uploads/images/articles/' . date('Y') . '/' . date('m')), $imageName);
|
||||
$picture->move(
|
||||
storage_path(sprintf('app/public/modelfiles/articles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
$imageName_r = Str::slug($title) . '-jeusselin-' . date('d-m-Y') . '_r.' . $picture_r->extension();
|
||||
$picture_r->move(public_path('uploads/images/articles/' . date('Y') . '/' . date('m')), $imageName_r);
|
||||
$picture_r->move(
|
||||
storage_path(sprintf('app/public/modelfiles/articles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName_r
|
||||
);
|
||||
|
||||
$a = new Articles();
|
||||
$a->title = $title;
|
||||
$a->slug = $slug;
|
||||
$a->picture = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
$a->picture_r = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName_r;
|
||||
$a->picture = sprintf('storage/modelfiles/articles/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
$a->picture_r = sprintf('storage/modelfiles/articles/%s/%s/%s', date('Y'), date('m'), $imageName_r);
|
||||
$a->content = $content;
|
||||
$a->category_id = $categoryId;
|
||||
$a->status = $status;
|
||||
|
|
@ -107,8 +113,8 @@ class ArticlesController extends Controller
|
|||
$a = Articles::findOrFail($id);
|
||||
$ac = ArticlesCategories::all();
|
||||
return view('bo.articles.edit')
|
||||
->with('a', $a)
|
||||
->with('ac', $ac);
|
||||
->with('a', $a)
|
||||
->with('ac', $ac);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
|
|
@ -144,27 +150,33 @@ class ArticlesController extends Controller
|
|||
$a = Articles::findOrFail($id);
|
||||
|
||||
if ($picture !== null) {
|
||||
if (file_exists(public_path() . '/' . $a->picture)) {
|
||||
unlink(public_path() . '/' . $a->picture);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture)));
|
||||
}
|
||||
$imageName = Str::slug($title) . '.' . $picture->extension();
|
||||
$picture->move(public_path('uploads/images/articles/' . date('Y') . '/' . date('m') . '/'), $imageName);
|
||||
$picture->move(
|
||||
storage_path(sprintf('app/public/modelfiles/articles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
}
|
||||
if ($picture_r !== null) {
|
||||
if (file_exists(public_path() . '/' . $a->picture_r)) {
|
||||
unlink(public_path() . '/' . $a->picture_r);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture_r)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture_r)));
|
||||
}
|
||||
$imageName_r = Str::slug($title) . '_r.' . $picture_r->extension();
|
||||
$picture_r->move(public_path('uploads/images/articles/' . date('Y') . '/' . date('m') . '/'), $imageName_r);
|
||||
$picture_r->move(
|
||||
storage_path(sprintf('app/public/modelfiles/articles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName_r
|
||||
);
|
||||
}
|
||||
|
||||
$a->title = $title;
|
||||
$a->slug = $slug;
|
||||
if ($picture !== null) {
|
||||
$a->picture = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
$a->picture = sprintf('storage/modelfiles/articles/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
}
|
||||
if ($picture_r !== null) {
|
||||
$a->picture_r = 'uploads/images/articles/' . date('Y') . '/' . date('m') . '/' . $imageName_r;
|
||||
$a->picture_r = sprintf('storage/modelfiles/articles/%s/%s/%s', date('Y'), date('m'), $imageName_r);
|
||||
}
|
||||
$a->content = $content;
|
||||
$a->category_id = $categoryId;
|
||||
|
|
@ -191,11 +203,11 @@ class ArticlesController extends Controller
|
|||
{
|
||||
$a = Articles::findOrFail($id);
|
||||
|
||||
if (file_exists(public_path() . '/' . $a->picture)) {
|
||||
unlink(public_path() . '/' . $a->picture);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture)));
|
||||
}
|
||||
if (file_exists(public_path() . '/' . $a->picture_r)) {
|
||||
unlink(public_path() . '/' . $a->picture_r);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture_r)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $a->picture_r)));
|
||||
}
|
||||
|
||||
if ($a->deleteOrFail()) {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,10 @@ class EmployeesController extends Controller
|
|||
]);
|
||||
|
||||
$imageName = Str::slug($firstname . "-" . $lastname) . '-jeusselin.' . $photo->extension();
|
||||
$photo->move(public_path('uploads/images/profiles/' . date('Y') . '/' . date('m')), $imageName);
|
||||
$photo->move(
|
||||
storage_path(sprintf('app/public/modelfiles/profiles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
|
||||
$e = new Employees();
|
||||
$e->civility = $request->civility;
|
||||
|
|
@ -63,7 +66,7 @@ class EmployeesController extends Controller
|
|||
$e->firstname = $firstname;
|
||||
$e->job_title = $request->job_title;
|
||||
$e->video = $video;
|
||||
$e->photo = 'uploads/images/profiles/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
$e->photo = sprintf('storage/modelfiles/profiles/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
$e->order = $this->getLastOrder();
|
||||
$e->save();
|
||||
|
||||
|
|
@ -128,11 +131,14 @@ class EmployeesController extends Controller
|
|||
$e = Employees::findOrFail($id);
|
||||
|
||||
if ($photo !== null) {
|
||||
if (file_exists(public_path() . '/' . $e->photo)) {
|
||||
unlink(public_path() . '/' . $e->photo);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $e->photo)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $e->photo)));
|
||||
}
|
||||
$imageName = Str::slug($firstname . "-" . $lastname) . '-jeusselin.' . $photo->extension();
|
||||
$photo->move(public_path('uploads/images/profiles/' . date('Y') . '/' . date('m')), $imageName);
|
||||
$photo->move(
|
||||
storage_path(sprintf('app/public/modelfiles/profiles/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
}
|
||||
|
||||
$e->civility = $request->civility;
|
||||
|
|
@ -141,7 +147,7 @@ class EmployeesController extends Controller
|
|||
$e->job_title = $request->job_title;
|
||||
$e->video = $video;
|
||||
if ($photo !== null) {
|
||||
$e->photo = 'uploads/images/profiles/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
$e->photo = sprintf('storage/modelfiles/profiles/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
}
|
||||
$e->saveOrFail();
|
||||
|
||||
|
|
@ -167,10 +173,12 @@ class EmployeesController extends Controller
|
|||
{
|
||||
$e = Employees::findOrFail($id);
|
||||
|
||||
if (file_exists(public_path() . '/' . $e->photo)) {
|
||||
unlink(public_path() . '/' . $e->photo);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $e->photo)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $e->photo)));
|
||||
}
|
||||
|
||||
$e->businessSectors()->detach();
|
||||
|
||||
// prise en charge de la liaison avec les secteurs
|
||||
if ($e->deleteOrFail()) {
|
||||
return redirect()
|
||||
|
|
|
|||
|
|
@ -54,13 +54,16 @@ class HomeSlidersController extends Controller
|
|||
]);
|
||||
|
||||
$imageName = Str::slug($title) . '-jeusselin.' . $picture->extension();
|
||||
$picture->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName);
|
||||
$picture->move(
|
||||
storage_path(sprintf('app/public/modelfiles/slider_accueil/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
// $imageName_r = Str::slug($title) .'-jeusselin_r.'.$picture_r->extension();
|
||||
// $picture_r->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r);
|
||||
// $picture_r->move(storage_path('modelfiles/slider_accueil/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r);
|
||||
$hsp = new HomeSliders();
|
||||
$hsp->title = $title;
|
||||
$hsp->picture = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
// $hsp->picture_r = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName_r;
|
||||
$hsp->picture = sprintf('storage/modelfiles/slider_accueil/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
// $hsp->picture_r = 'storage/modelfiles/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName_r;
|
||||
$hsp->text = $text;
|
||||
$hsp->link_label = $linkLabel;
|
||||
$hsp->link = $link;
|
||||
|
|
@ -104,7 +107,7 @@ class HomeSlidersController extends Controller
|
|||
$title = $request->title;
|
||||
$picture = $request->picture;
|
||||
$picture_r = null;
|
||||
// $request->picture_r;
|
||||
// $request->picture_r;
|
||||
$text = $request->text;
|
||||
$linkLabel = $request->link_label;
|
||||
$link = $request->link;
|
||||
|
|
@ -135,26 +138,32 @@ class HomeSlidersController extends Controller
|
|||
$hsp = HomeSliders::findOrFail($id);
|
||||
|
||||
if ($picture !== null) {
|
||||
if (file_exists(public_path() . '/' . $hsp->picture)) {
|
||||
unlink(public_path() . '/' . $hsp->picture);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $hsp->picture)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $hsp->picture)));
|
||||
}
|
||||
$imageName = Str::slug($title) . '-jeusselin.' . $picture->extension();
|
||||
$picture->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName);
|
||||
$picture->move(
|
||||
storage_path(sprintf('app/public/modelfiles/slider_accueil/%s/%s', date('Y'), date('m'))),
|
||||
$imageName
|
||||
);
|
||||
}
|
||||
if ($picture_r !== null) {
|
||||
if (file_exists(public_path() . '/' . $hsp->picture_r)) {
|
||||
unlink(public_path() . '/' . $hsp->picture_r);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $hsp->picture_r)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $hsp->picture_r)));
|
||||
}
|
||||
$imageName_r = Str::slug($title) . '-jeusselin_r.' . $picture_r->extension();
|
||||
$picture_r->move(public_path('uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/'), $imageName_r);
|
||||
$picture_r->move(
|
||||
storage_path(sprintf('app/public/modelfiles/slider_accueil/%s/%s', date('Y'), date('m'))),
|
||||
$imageName_r
|
||||
);
|
||||
}
|
||||
|
||||
$hsp->title = $title;
|
||||
if ($picture !== null) {
|
||||
$hsp->picture = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName;
|
||||
$hsp->picture = sprintf('storage/modelfiles/slider_accueil/%s/%s/%s', date('Y'), date('m'), $imageName);
|
||||
}
|
||||
if ($picture_r !== null) {
|
||||
$hsp->picture_r = 'uploads/images/slider_accueil/' . date('Y') . '/' . date('m') . '/' . $imageName_r;
|
||||
$hsp->picture_r = sprintf('storage/modelfiles/slider_accueil/%s/%s/%s', date('Y'), date('m'), $imageName_r);
|
||||
}
|
||||
$hsp->text = $text;
|
||||
$hsp->link_label = $linkLabel;
|
||||
|
|
@ -184,12 +193,12 @@ class HomeSlidersController extends Controller
|
|||
{
|
||||
$h = HomeSliders::findOrFail($id);
|
||||
|
||||
if (file_exists(public_path() . '/' . $h->picture)) {
|
||||
unlink(public_path() . '/' . $h->picture);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $h->picture)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $h->picture)));
|
||||
}
|
||||
if (!is_null($h->picture_r)) {
|
||||
if (file_exists(public_path() . '/' . $h->picture_r)) {
|
||||
unlink(public_path() . '/' . $h->picture_r);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $h->picture_r)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $h->picture_r)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class PublicPdfsController extends Controller
|
|||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'pdffile' => ['required','mimes:application/pdf,pdf','max:2048'],
|
||||
'pdffile' => ['required', 'mimes:application/pdf,pdf', 'max:2048'],
|
||||
]);
|
||||
|
||||
|
||||
|
|
@ -37,11 +37,15 @@ class PublicPdfsController extends Controller
|
|||
|
||||
|
||||
$fileName = Str::slug(pathinfo($pdffile->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . pathinfo($pdffile->getClientOriginalName(), PATHINFO_EXTENSION);
|
||||
$pdffile->move(public_path('uploads/pdf/' . Str::slug($category->name) . '/' . date('Y') . '/' . date('m')), $fileName);
|
||||
$pdffile->move(
|
||||
storage_path(sprintf('app/public/modelfiles/public_pdfs/%s/%s/%s', Str::slug($category->name), date('Y'), date('m'))),
|
||||
$fileName
|
||||
);
|
||||
|
||||
$pdf = new PublicPdfs();
|
||||
$pdf->file_name = $pdffile->getClientOriginalName();
|
||||
$pdf->file_path = sprintf('storage/modelfiles/public_pdfs/%s/%s/%s/%s', Str::slug($category->name), date('Y'), date('m'), $fileName);
|
||||
|
||||
$pdf = new PublicPdfs();
|
||||
$pdf->file_name = $pdffile->getClientOriginalName();
|
||||
$pdf->file_path = 'uploads/pdf/' . Str::slug($category->name) . '/' . date('Y') . '/' . date('m') . '/' . $fileName;
|
||||
$pdf->is_published = $is_published;
|
||||
$pdf->category_id = $categoryId;
|
||||
|
||||
|
|
@ -61,15 +65,15 @@ class PublicPdfsController extends Controller
|
|||
$pdf = PublicPdfs::findOrFail($id);
|
||||
$pc = PdfCategories::all();
|
||||
return view('bo.public-pdfs.edit')
|
||||
->with('pdf', $pdf)
|
||||
->with('pc', $pc);
|
||||
->with('pdf', $pdf)
|
||||
->with('pc', $pc);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'pdffile' => ['mimes:application/pdf,pdf','max:2048'],
|
||||
'pdffile' => ['mimes:application/pdf,pdf', 'max:2048'],
|
||||
]);
|
||||
|
||||
$is_published = isset($request->is_published) ? true : false;
|
||||
|
|
@ -80,14 +84,17 @@ class PublicPdfsController extends Controller
|
|||
$pdf = PublicPdfs::findOrFail($id);
|
||||
|
||||
if ($pdffile !== null) {
|
||||
if (file_exists(public_path() . '/' . $pdf->file_path)) {
|
||||
unlink(public_path() . '/' . $pdf->file_path);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $pdf->file_path)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $pdf->file_path)));
|
||||
}
|
||||
$fileName = Str::slug(pathinfo($pdffile->getClientOriginalName(), PATHINFO_FILENAME)) . '.' . pathinfo($pdffile->getClientOriginalName(), PATHINFO_EXTENSION);
|
||||
$pdffile->move(public_path('uploads/pdf/' . Str::slug($category->name) . '/' . date('Y') . '/' . date('m')), $fileName);
|
||||
$pdffile->move(
|
||||
storage_path(sprintf('app/public/modelfiles/public_pdfs/%s/%s/%s', Str::slug($category->name), date('Y'), date('m'))),
|
||||
$fileName
|
||||
);
|
||||
|
||||
$pdf->file_name = $pdffile->getClientOriginalName();
|
||||
$pdf->file_path = 'uploads/pdf/' . Str::slug($category->name) . '/' . date('Y') . '/' . date('m') . '/' . $fileName;
|
||||
$pdf->file_path = sprintf('storage/modelfiles/public_pdfs/%s/%s/%s/%s', Str::slug($category->name), date('Y'), date('m'), $fileName);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -109,8 +116,8 @@ class PublicPdfsController extends Controller
|
|||
{
|
||||
$pdf = PublicPdfs::findOrFail($id);
|
||||
|
||||
if (file_exists(public_path() . '/' . $pdf->file_path)) {
|
||||
unlink(public_path() . '/' . $pdf->file_path);
|
||||
if (file_exists(storage_path(Str::replaceFirst('storage', 'app/public', $pdf->file_path)))) {
|
||||
unlink(storage_path(Str::replaceFirst('storage', 'app/public', $pdf->file_path)));
|
||||
}
|
||||
|
||||
if ($pdf->deleteOrFail()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue