本文整理汇总了PHP中app\File::find方法的典型用法代码示例。如果您正苦于以下问题:PHP File::find方法的具体用法?PHP File::find怎么用?PHP File::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\File
的用法示例。
在下文中一共展示了File::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadThumbAndMainImage
public function uploadThumbAndMainImage(Request $request)
{
// get basic info
$s3 = Storage::disk('s3');
$file = $request->file('file');
$extension = $request->file('file')->guessExtension();
$filename = uniqid() . '.' . $extension;
$mimeType = $request->file('file')->getClientMimeType();
$fileSize = $request->file('file')->getClientSize();
$image = Image::make($file);
$galleryId = $request->input('galleryId');
// generate the thumb and medium image
$imageThumb = Image::make($file)->fit(320)->crop(320, 240, 0, 0);
$imageThumb->encode($extension);
$imageMedium = Image::make($file)->resize(800, null, function ($constraint) {
$constraint->aspectRatio();
});
$imageMedium->encode($extension);
$image->encode($extension);
// upload image to S3
$s3->put("gallery_{$galleryId}/main/" . $filename, (string) $image, 'public');
$s3->put("gallery_{$galleryId}/medium/" . $filename, (string) $imageMedium, 'public');
$s3->put("gallery_{$galleryId}/thumb/" . $filename, (string) $imageThumb, 'public');
// make image entry to DB
$file = File::create(['file_name' => $filename, 'mime_type' => $mimeType, 'file_size' => $fileSize, 'file_path' => env('S3_URL') . "gallery_{$galleryId}/main/" . $filename, 'type' => 's3']);
DB::table('gallery_images')->insert(['gallery_id' => $galleryId, 'file_id' => $file->id]);
$fileImg = File::find($file->id);
$fileImg->status = 1;
$fileImg->save();
return ['file' => $fileImg, 'file_id' => $file->id, 'thumbUrl' => env('S3_URL') . "gallery_{$galleryId}/thumb/" . $filename, 'url' => env('S3_URL') . "gallery_{$galleryId}/medium/" . $filename, 'main' => env('S3_URL') . "gallery_{$galleryId}/main/" . $filename];
}
示例2: destroy
public function destroy($userId, $fileId)
{
$file = \App\File::find($fileId);
$storagePath = storage_path() . '/documentos/' . $userId;
$file->delete();
unlink($storagePath . '/' . $file->name);
return redirect()->back()->with('success', 'Arquivo removido com sucesso!');
}
示例3: deleteArticleAttachment
public function deleteArticleAttachment(Request $request)
{
$user = Auth::user();
$file = File::find($request->input('attachment'));
if ($user->id == $file->user_id) {
$file->delete();
}
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$file = File::find($id);
$file->version_id = $request->input('version_id');
$file->source = $request->input('source');
$file->name = $request->input('name');
$file->save();
}
示例5: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$file = File::find($id);
if (is_null($file)) {
return response()->json(['error' => 'No file found with ID ' . $id], 404);
}
$file->delete();
unlink(public_path('assets/files/' . $file->contact->name . '/' . $file->name));
return $file;
}
示例6: assignFile
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function assignFile(Request $request)
{
$file = File::find($request->input('fileId'));
if ($file != NULL && $request->has($file->version_id)) {
$file->version_id = $request->input('versionId');
$file->save();
} else {
abort(500, $file . 'This file already assigned with a version!');
}
}
示例7: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$file = File::find($id);
if ($file) {
FileManager::delete(public_path() . $file->path);
$file->delete();
return response()->json(['data' => "The file with id {$file->id} was removed"], 200);
}
return response()->json(['message' => 'Does not exist a file with that id'], 404);
}
示例8: getDownload
public function getDownload($id)
{
$file = File::find($id);
$s3 = Storage::disk('s3');
if ('s3' == $file->type) {
$fileUrl = env('S3_URL') . $file->file_path;
return $fileUrl;
}
// $downloadUrl = $s3->getObjectUrl(env('S3_BUCKET'), 'data.txt', '+5 minutes', array(
// 'ResponseContentDisposition' => 'attachment; filename="' . $file->fileName . '"',
// ));
// $filePath = $this->filePath . $file->file_name;
// return response()->download($filePath);
}
示例9: createDownload
/**
* Create photos matching given share id download response.
*
* @param int|string $id
* @return string
*/
public function createDownload()
{
$items = $this->splitFilesAndFolders();
$downloads = [];
foreach ($items['folders'] as $id) {
$downloads = $this->addFolder($id, $downloads);
}
foreach ($items['files'] as $id) {
$file = File::find($id);
$downloads[$this->getName($file)] = $file->getAbsolutePath();
}
$fileName = $this->createZip(base_path('storage/zips'), $downloads);
return $fileName;
}
示例10: delete
public function delete(Request $request)
{
if (isset($request->id)) {
$upload = File::find($request->id);
$upload->delete();
unlink(public_path('uploads/files/' . $upload->filename));
unlink(public_path('uploads/files/thumb_' . $upload->filename));
if (!isset(File::find($request->id)->filename)) {
$success = new stdClass();
$success->{$upload->filename} = true;
return Response::json(array('files' => array($success)), 200);
}
}
}
示例11: LogBrowse
public static function LogBrowse($file_id)
{
$fileInfo = File::find(intval($file_id));
if ($fileInfo == null) {
return false;
}
$fileInfo->view_times += 1;
$fileInfo->save();
$log = new BrowseLog();
$log->page = $file_id;
$log->ip = LogController::getIP();
$log->user_agent = LogController::getUA();
$log->save();
return true;
}
示例12: get
public function get($id)
{
// $entry = File::where('filename', '=', $filename)->firstOrFail();
// $file = \Storage::disk('local')->get($entry->filename);
// // return (new \Response($file, 200))
// // ->header('Content-Type', $entry->mime);
// return response($file,200)
// ->header('Content-Type', $entry->mime);
// ===============================================================================================
// $entry = File::where('filename', '=', $filename)->firstOrFail();
// if (\Storage::exists($entry->filename)) {
// $file = \Storage::disk('local')->get($entry->filename);
// // return (new \Response($file, 200))
// // ->header('Content-Type', $entry->mime);
// return response($file,200)
// ->header('Content-Type', $entry->mime);
// }
// else{
// return 'File Rusak atau tidak ditemukan, Silahkan Update Ulang ';
// }
$entry = File::find(base64_decode($id));
// dd($entry);
if ($entry) {
$dirfile = empty($entry->nama_baru) ? $entry->filename : $entry->dir . '/' . $entry->nama_baru;
// echo $dirfile;
// ARSIPPROSESSP2D-UYUYphpFDCC.tmp.pdf
// dinas-p/ARSIPPROSESSP2D-UYUYphpF441.tmp.pdf
// dd($dirfile);
// dd($dirfile);
// "SEKWAN-II/164-sp2d-nhl-setwn-09-arsipprosessp2d-164-sp2d-nhl-setwn-09-phpCAC5.tmp.pdf";
// "164-sp2d-nhl-setwn-09-arsipprosessp2d-164-sp2d-nhl-setwn-09-1-php757E.tmp"
if (\Storage::exists($dirfile)) {
$file = \Storage::get($dirfile);
// return (new \Response($file, 200))
// ->header('Content-Type', $entry->mime);
return response($file, 200)->header('Content-Type', $entry->mime);
} elseif (!empty($entry->filename) && \Storage::exists($entry->filename)) {
$file = \Storage::get($entry->filename);
// return (new \Response($file, 200))
// ->header('Content-Type', $entry->mime);
return response($file, 200)->header('Content-Type', $entry->mime);
} else {
return 'File tidak ditemukan, Silahkan Update Ulang ';
}
} else {
return 'Data File Rusak atau tidak ditemukan, Silahkan Update Ulang ';
}
}
示例13: handle
/**
* Handle the event.
*
* @param UserUpdated $event
* @return void
*/
public function handle(UserUpdated $event)
{
$user = $event->user;
$dirty = $user->getDirty();
$original = $user->getOriginal();
if (array_key_exists('government_identification_id', $dirty)) {
$file = File::find($original['government_identification_id']);
if ($file) {
$file->delete();
}
}
if (array_key_exists('avatar_id', $dirty)) {
$file = File::find($original['avatar_id']);
if ($file) {
$file->delete();
}
}
}
示例14: postImageDelete
public function postImageDelete(Request $request)
{
$file = File::find($request->get('id'))->delete();
return response()->json(['status' => 'success'], 200);
}
示例15: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
if (!Auth::user()->can('edit-video')) {
return view('errors.denied');
}
$file = File::find($id);
return view('video.edit')->with('file', $file);
}