public function getThumbnail(Request $request, Upload $upload) { if (!$request->user() || $request->user()->id !== $upload->user_id && !$request->user()->isPrivilegedUser()) { return abort(StatusCode::NOT_FOUND); } return response()->download($upload->getThumbnailPath(true), 'thumbnail.' . $upload->name); }
/** * Delete the file when the model is being deleted. * * @param Upload $upload * * @return bool */ public function deleting(Upload $upload) { // Only allow deletion if the file can be deleted. if (unlink($upload->getCompletePath())) { return true; } return false; }
public function upload() { $upload = new Models\Upload(); $upload->action($_FILES); if ($upload->error) { $this->json = new Models\Json(); header('Location: index.php?p=home&message=' . $upload->message); } else { header('Location: index.php?p=details&imageName=' . $upload->nommd5); } }
/** * Handle sending a file, preferably by offloading to the webserver. * * @param Upload $upload * @return mixed */ public static function sendFile(Upload $upload) { switch (config('upste.sendfile_method')) { case 'x-accel': return response()->make()->header('X-Accel-Redirect', '/' . $upload->getPath())->header('Content-Type', '')->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name)); break; case 'x-sendfile': return response()->make()->header('X-Sendfile', $upload->getPath(true))->header('Content-Type', '')->header('Content-Disposition', sprintf('inline; filename="%s"', $upload->original_name)); break; default: return response()->download($upload->getPath(true), $upload->original_name); } }
public function get(Request $request, Upload $upload) { if (Storage::exists($upload->getPath())) { if ($upload->user->banned) { Log::info('Refusing to serve file for banned user.', ['user' => $upload->user->name, 'file' => $upload->name]); return abort(StatusCode::NOT_FOUND); } if (!$request->user() || $request->user()->id !== $upload->user_id) { $cacheKey = sprintf('cached_view:%s:%s', $request->ip(), $upload->name); if (!Cache::has($cacheKey)) { Cache::put($cacheKey, 1, 60); DB::table('uploads')->where('id', $upload->id)->increment('views'); } } return Helpers::sendFile($upload); } return abort(StatusCode::NOT_FOUND); }
/** * @return int */ public function actionIndex() { // проверяем существует есть ли файл $filename = \Yii::$app->basePath . '/web/files/upload.xlsx'; // \Yii::info(\yii\helpers\Json::encode(['fdsfds'=>'test']), 'cron'); if (file_exists($filename)) { // проверяем наличие запущенного процесса if (Upload::findOne(['status' => 0])) { return 0; } else { $model = new Upload(); $model->status = 0; $model->task = 'Инф.продукт'; $model->save(); //Вызываем компонент парсинга excel $component = new ExcelComponent(); $component->uploadInformProduct(); $model->status = 1; $model->save(); } } return 0; }
public function download() { $this->data['title'] = 'Download File'; $this->data['download'] = Models\Upload::orderBy('tgl_posting')->paginate(10); return view('front.download', $this->data); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // File Delete By Agus Cahyono $file_lama = DB::table('tbl_download')->select('nama_file')->where('id_download', $id)->first(); File::delete('upload/file/' . $file_lama->nama_file); $data = Upload::find($id); if ($data->delete()) { return response()->json(array('success' => TRUE, 'msg' => 'Data Berhasil Dihapus')); } }
/** * Save the changes. * * @param Upload $upload * * @return bool */ public function persist(Upload $upload) { $upload->name = $this->input('name', $upload->name); return $upload->save(); }
/** * Boot model observers. */ public function boot() { Upload::observe(UploadObserver::class); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $data = Upload::find($id); if ($data->delete()) { return response()->json(array('success' => TRUE, 'msg' => 'Data Berhasil Dihapus')); } }
public function actionInform() { $upload = Upload::find()->orderBy(['id' => SORT_DESC])->all(); return $this->render('inform', ['upload' => $upload]); }
public function post(Request $request) { if (!$request->hasFile('file')) { return response()->json([trans('messages.upload_file_not_found')], StatusCode::BAD_REQUEST); } $uploadedFile = $request->file('file'); if (!$uploadedFile->isValid()) { return response()->json([trans('messages.invalid_file_upload')], StatusCode::BAD_REQUEST); } if ($uploadedFile->getSize() >= config('upste.upload_limit')) { $responseMsg = trans('messages.upload_too_large', ['limit' => Helpers::formatBytes(config('upste.upload_limit'))]); return response()->json([$responseMsg], StatusCode::REQUEST_ENTITY_TOO_LARGE); } // If this upload would hit the quota defined in .env, reject it. if (config('upste.user_storage_quota') > 0 && !$request->user()->isPrivilegedUser() && $request->user()->getUploadsSize() + $uploadedFile->getSize() >= config('upste.user_storage_quota')) { $responseMsg = trans('messages.reached_upload_limit', ['limit' => Helpers::formatBytes(config('upste.user_storage_quota'))]); return response()->json([$responseMsg], StatusCode::FORBIDDEN); } $ext = Helpers::detectFileExtension($uploadedFile); $originalHash = sha1_file($uploadedFile); $originalName = $uploadedFile->getClientOriginalName(); // Check to see if we already have this file for this user. $existing = Upload::whereOriginalHash($originalHash)->whereUserId($request->user()->id)->first(); if ($existing) { $result = ['url' => route('files.get', $existing), 'delete_url' => route('account.uploads.delete', $existing)]; $existing->original_name = $originalName; $existing->save(); return response()->json($result, StatusCode::CREATED)->setJsonOptions(JSON_UNESCAPED_SLASHES); } $randomLen = config('upste.upload_slug_length'); do { $newName = str_random($randomLen++) . ".{$ext}"; } while (Upload::whereName($newName)->first() || $newName === 'index.php'); $upload = new Upload(['user_id' => $request->user()->id, 'name' => $newName, 'original_name' => $originalName, 'original_hash' => $originalHash]); $uploadFileHandle = fopen($uploadedFile->getRealPath(), 'rb'); Storage::put($upload->getPath(), $uploadFileHandle); fclose($uploadFileHandle); if (Helpers::isImage($uploadedFile)) { try { $img = Image::make($uploadedFile); } catch (NotReadableException $ex) { Log::error($ex); return response()->json([trans('messages.could_not_read_image')], StatusCode::INTERNAL_SERVER_ERROR); } catch (NotSupportedException $ex) { Log::error($ex); return response()->json([trans('messages.unsupported_image_type')], StatusCode::INTERNAL_SERVER_ERROR); } try { $upload->createDirs(); $img->backup(); $img->fit(128, 128)->save($upload->getThumbnailPath(true)); $img->reset(); if (Helpers::shouldStripExif($uploadedFile)) { $img->save($upload->getPath(true)); } } catch (NotWritableException $ex) { Log::error($ex); $upload->deleteDirs(); return response()->json([trans('messages.could_not_write_image')], StatusCode::INTERNAL_SERVER_ERROR); } finally { $img->destroy(); } } $savedFile = $upload->getPath(true); $upload->hash = sha1_file($savedFile); $upload->size = filesize($savedFile); $upload->save(); $result = ['url' => route('files.get', $upload), 'delete_url' => route('account.uploads.delete', $upload)]; return response()->json($result, StatusCode::CREATED)->setJsonOptions(JSON_UNESCAPED_SLASHES); }