本文整理汇总了PHP中app\File::save方法的典型用法代码示例。如果您正苦于以下问题:PHP File::save方法的具体用法?PHP File::save怎么用?PHP File::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\File
的用法示例。
在下文中一共展示了File::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postUpload
/**
*
*/
public function postUpload(Request $req, $db)
{
$response = array();
$file = $req->file('excelF');
/*periksa type file excel ======================================================================================*/
if ($file && ($file->getClientMimeType() == 'application/vnd.ms-excel' or $file->getClientMimeType() == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) {
$extension = $file->getClientOriginalExtension();
$filename = $file->getClientOriginalName();
if (\Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
// simpan kedadalam table
$entry = new File();
$entry->mime = $file->getClientMimeType();
$entry->original_filename = $file->getClientOriginalName();
$entry->filename = $file->getFilename() . '.' . $extension;
$entry->description = $req->get('description', ' Tanpa Deskripsi ! ');
$entry->db_table = $db;
$entry->users_id = \Sentry::getUser()->id;
$entry->save();
$response['code'] = 200;
$response['msg'] = "File {$entry->original_filename} Telah disimpan";
return $response;
}
} elseif ($req->file('excelF')) {
$extension = $file->getClientOriginalExtension();
$filename = $file->getClientOriginalName();
$response['code'] = 404;
$response['msg'] = "File berextensi {$extension} dengan nama {$filename}, file Seharusnya Berupa Excel";
// $response['msg']="File Anda $file->getClientOriginalName(), Pastikan File yang Anda upload sesuai dengan format ";
return $response;
// return $response;
} else {
$response['code'] = 404;
$response['msg'] = "Anda belum mimilih format file untuk diupload !!!";
return json_encode($response);
}
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
//
$file = new File();
//$file->size = $request->file('upload')->getSize();
$file->name = $request->name;
$file->save();
$fileName = $file->id . '.' . $request->file('upload')->getClientOriginalExtension();
$file->size = $request->file('upload')->getSize();
$request->file('upload')->move(base_path() . '/public/fileuploads/', $fileName);
$file->url = '/fileuploads/' . $fileName;
$file->save();
return redirect('files');
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
//
// $v = Validator::make($request, [
// 'type' => 'required',
// ]);
// if ($v->fails())
// {
// return redirect()->back()->withErrors($v->errors())
// ->withInput();
// }else{
//check for uploaded file and store it n public path
$file = new File();
$file->name = $request->get('name');
$file->desc = $request->get('desc');
$file->type = $request->get('type');
if ($request->hasFile('file')) {
$destination = 'files/';
$filename = str_random(6) . "_" . $request->file('file')->getClientOriginalName();
$request->file('file')->move($destination, $filename);
$file->file = $filename;
} else {
$file->file = $request->get('file');
}
$file->save();
// }
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$file = new File();
$file->fill($request->all());
$file->save();
return $file;
}
示例5: IdentitasHandle
public function IdentitasHandle($req, $id)
{
// PDF tidak di update / melalui form
// Gagal mengupload file PDF
// Sukses Mengupload DOkumen
$temp_iden_pesan = ['error' => ['user' => 'Peringatan : File PDF tidak di atur dengan benar !', 'sistem' => 'Terjadi kesalahan upload File PDf '], 'succes' => ['store' => 'Sukses mengupload Dokumen PDF ', 'update' => 'Sukses mengupdate Dokumen PDF ']];
$temp_file_pesan = ['error' => '', 'succes' => ''];
// dd($req->all());
$file = $req->file('gambar');
if ($file and $file->getClientMimeType() == 'application/pdf') {
// dd($file);
$extension = $file->getClientOriginalExtension();
$FileIdentity = File::where('dokumen_id', $id);
// Update
if (count($FileIdentity->get()->toArray())) {
$this->result['identitas']['lama'] = $FileIdentity->get()->toArray();
//delete file
$data_for_update = ['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $file->getFilename() . '.' . $extension];
if ($FileIdentity->update($update)) {
$this->result['identitas']['baru'] = $FileIdentity->get()->toArray();
$this->{$result}['pesan'] = $temp_iden_pesan['succes']['update'];
// proses storage
if (\Storage::delete($FileIdentity->get()->toArray()[0]['filename']) && \Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
$this->file_pesan['succes'] = $temp_file_pesan['succes'];
return true;
} else {
$this->file_pesan['error'] = $temp_file_pesan['error'];
return false;
}
return true;
} else {
return false;
}
} else {
// echo " new file";
$new_dokument = new File();
$new_dokument->dokumen_id = $id;
$new_dokument->mime = $file->getClientMimeType();
$new_dokument->original_filename = $file->getClientOriginalName();
$new_dokument->filename = $file->getFilename() . '.' . $extension;
//new identitas
if ($new_dokument->save()) {
// new pdf
if (\Storage::disk('local')->put($file->getFilename() . '.' . $extension, \File::get($file))) {
return true;
}
$this->{$result}['pesan'] = $temp_iden_pesan['succes']['store'];
return true;
} else {
$this->{$result}['pesan'] = $temp_iden_pesan['error']['sistem'];
return false;
}
}
// }
} else {
$this->{$result}['pesan'] = $temp_iden_pesan['error']['user'];
return false;
}
}
示例6: addNew
public static function addNew($name, $file, $description = '', $patient_id = 0)
{
$new_file = new File();
$new_file->name = $name;
$new_file->description = $description;
$new_file->patient_id = $patient_id;
$new_file->save();
$new_file->assignIcon($file->getClientOriginalExtension());
$new_file->saveFile($file);
return $new_file;
}
示例7: store
public function store(FileRequest $request)
{
if ($this->exist($request->input('num_file'))) {
return redirect()->to('expedientes/create')->withInput()->withErrors(array('invalid' => 'Ya existe el expediente por favor digite uno distinto'));
}
$date = Carbon::now();
$file = new File($request->all());
$file->created_at = $date;
$file->updated_at = $date;
$file->save();
return redirect()->route('expedientes.index');
}
示例8: handleCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function handleCreate()
{
$user_id = Auth::id();
$user = User::find($user_id);
$user_name = $user->first_name;
$date = HelperController::convertCurrentTime();
$file = Input::file('file');
$extension = $file->getClientOriginalExtension();
// getting file extension
$fileName = $file->getClientOriginalName();
//$fileName= HelperController::explodefile($fileName);//explode the file name and file's extension and retrieve only file name
$path = '/files/' . $user_name . '/' . $date . '/' . $extension;
$destinationPath = public_path() . $path;
// upload path
$upload_success = $file->move($destinationPath, $fileName);
// uploading file to given path
if ($upload_success) {
$file_name_from_db = HelperController::checkFileName($fileName);
$file_path_from_db = HelperController::checkFilePath($path);
if ($fileName != $file_name_from_db && $path != $file_path_from_db) {
/*
* file data is stored in database
*
*/
$db_file = new File();
$db_file->file_name = $fileName;
$db_file->file_path = 'files/' . $user_name . '/' . $date . '/' . $extension;
$db_file->save();
$db_file->members()->attach($user_id);
//check file extension from extension collection
$ext_from_db = HelperController::checkExtension($extension);
if ($extension != $ext_from_db) {
$db_file_extension = new Extension();
$db_file_extension->file_extension = $extension;
$db_file_extension->save();
$db_file_extension->files()->attach($db_file);
} elseif ($extension == $ext_from_db) {
//$old_extension= Extension::where('file_extension','=',$extension)->first();
//$extension_id=$old_extension->id;
$ext_id = HelperController::getExtensionId($extension);
$db_file->extensions()->attach($ext_id);
}
}
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
//echo $file;
}
示例9: AddFile
public static function AddFile($arr)
{
if ($arr == null) {
return false;
}
$file = new File();
$file->filename = $arr['filename'];
$file->banned = 0;
$file->size = $arr['size'];
$file->description = $arr['description'];
$file->file_path = $arr['filepath'];
$file->uploader = $arr['uploader'];
$file->download_times = 0;
$file->view_times = 0;
$file->save();
return $file->id;
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$sub = new File();
$sub->name = "";
$sub->original_name = "";
$sub->description = "Poster template";
$sub->type = "";
$sub->img_type = "paper";
$sub->save();
$sub = new File();
$sub->name = "";
$sub->original_name = "";
$sub->description = "Poster template";
$sub->type = "";
$sub->img_type = "poster";
$sub->save();
}
示例11: upload
/**
* Upload and save file description.
*
* @param Symfony\Component\HttpFoundation\File\UploadedFile
* @return App\File
*/
public static function upload($uploadedFile)
{
if ($uploadedFile != null) {
$ext = $uploadedFile->getClientOriginalExtension();
$saved_name = str_random(20) . '.' . $ext;
$uploadedFile->move(storage_path() . '/upload', $saved_name);
// we should save this file information in database
$name = $uploadedFile->getClientOriginalName();
$ext = $uploadedFile->getClientOriginalExtension();
$mime = (new MimeTypeGuesser())->guess($ext);
$size = $uploadedFile->getClientSize();
$file = compact('saved_name', 'name', 'mime', 'size');
$file = new File($file);
$file->save();
return $file;
}
return null;
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Motion $motion, Request $request)
{
if (!Auth::user()->can('create-motions')) {
abort(401, 'You do not have permission to create a motion');
}
$file = new File();
$file->uploadFile('motion_files', 'file', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$motionFile = new MotionFile();
$motionFile->motion_id = $motion->id;
$motionFile->file_id = $file->id;
if (!$motionFile->save()) {
abort(403, $motionFile->errors);
}
return $motionFile;
}
示例13: newReview
public function newReview(Request $request)
{
$this->validate($request, ['review_name' => 'required|max:255', 'file' => 'required']);
$id = uniqid();
$name = $request->input('review_name');
$file = $request->file('file');
$review = new Review();
$review->id = $id;
$review->name = $name;
$review->save();
if ($file->getMimeType() == 'application/zip') {
$zip = zip_open($request->file('file')->getPathName());
if (is_resource($zip)) {
while ($zip_entry = zip_read($zip)) {
$name = zip_entry_name($zip_entry);
$size = zip_entry_filesize($zip_entry);
if (zip_entry_open($zip, $zip_entry, 'r')) {
$contents = zip_entry_read($zip_entry, $size);
$finfo = new \finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer($contents);
if (in_array($type, File::$AcceptTypes) && File::IsValidNameName($name)) {
$dbFile = new File();
$dbFile->review_id = $id;
$dbFile->contents = $contents;
$dbFile->type = $type;
$dbFile->name = $name;
$dbFile->size = $size;
$dbFile->save();
}
}
zip_entry_close($zip_entry);
}
}
} else {
$dbFile = new File();
$dbFile->review_id = $id;
$dbFile->contents = file_get_contents($request->file('file')->getPathname());
$dbFile->type = $file->getMimeType();
$dbFile->name = $file->getClientOriginalName();
$dbFile->size = $file->getClientSize();
$dbFile->save();
}
return redirect('reviews/' . $id);
}
示例14: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$validator = Validator::make(array('image' => Input::file('image')), array('image' => 'image'));
if ($validator->fails()) {
abort(403, 'file is not an image');
}
$file = new File();
$file->uploadFile('background_images', 'background_images', $request);
if (!$file->save()) {
abort(403, $file->errors);
}
$backgroundImage = (new BackgroundImage())->secureFill($request->all());
$backgroundImage->user_id = Auth::user()->id;
$backgroundImage->file_id = $file->id;
if (!$backgroundImage->save()) {
abort(403, $backgroundImage->errors);
}
return $backgroundImage;
}
示例15: postFilesCreate
/**
* Store a newly created resource in storage.
*
* @param FileUploadRequest $request
* @return Response
*/
public function postFilesCreate(FileUploadRequest $request)
{
$destinationPath = public_path() . '/uploads/files/';
$file_temp = $request->file('file');
$extension = $file_temp->getClientOriginalExtension() ?: 'png';
$safeName = str_random(10) . '.' . $extension;
$fileItem = new File();
$fileItem->filename = $safeName;
$fileItem->mime = $file_temp->getMimeType();
$fileItem->save();
$file_temp->move($destinationPath, $safeName);
Thumbnail::generate_image_thumbnail($destinationPath . $safeName, $destinationPath . 'thumb_' . $safeName);
$success = new stdClass();
$success->name = $safeName;
$success->size = $file_temp->getClientSize();
$success->url = $safeName;
$success->thumbnailUrl = URL::to('/uploads/files/thumb_' . $safeName);
$success->deleteUrl = URL::to('admin/file/delete?_token=' . csrf_token() . '&id=' . $fileItem->id);
$success->deleteType = 'DELETE';
$success->fileID = $fileItem->id;
return Response::json(array('files' => array($success)), 200);
}