/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function delete($id) { $file = Files::find($id); if (File::exists('public/upload/' . $file->src)) { File::delete('public/upload/' . $file->src); } $file->delete(); return response('done', 200); }
protected function uploadFiles($pageID, $fileData) { if (!File::isDirectory('uploads/' . $pageID)) { File::makeDirectory('uploads/' . $pageID); File::makeDirectory('uploads/' . $pageID . '/thumb'); } $files = Input::file('images'); $file_count = count($files); $uploadcount = 0; foreach ($files as $file) { $rules = array('file' => 'required'); // 'required|mimes:png,gif,jpeg,txt,pdf,doc' $validator = Validator::make(array('file' => $file), $rules); if ($validator->passes()) { $destinationPath = 'uploads/' . $pageID; $filename = $file->getClientOriginalName(); $upload_success = $file->move($destinationPath, $filename); $photo = new Files(); $photo->name = $filename; $photo->file_name = $filename; $photo->pages_id = $pageID; if ($file_count - 1 == $uploadcount) { $photo->masterPhoto = 1; } $photo->save(); $img = \Image::make('uploads/' . $pageID . '/' . $filename); $img->resize(320, 240); $img->save('uploads/' . $pageID . '/thumb/' . $filename); $uploadcount++; } } if ($fileData['filename'] != null) { foreach ($fileData['filename'] as $key => $value) { $rowFile = Files::find($key); if (isset($fileData['remove'][$key])) { File::delete('uploads/' . $pageID . '/' . $rowFile->name); File::delete('uploads/' . $pageID . '/thumb/' . $rowFile->name); Files::find($key)->delete(); } $rowFile->file_name = $value; if (isset($fileData['masterPhoto'][$key])) { $rowFile->masterPhoto = 1; } $rowFile->save(); } } }