当前位置: 首页>>代码示例>>PHP>>正文


PHP File::extension方法代码示例

本文整理汇总了PHP中File::extension方法的典型用法代码示例。如果您正苦于以下问题:PHP File::extension方法的具体用法?PHP File::extension怎么用?PHP File::extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在File的用法示例。


在下文中一共展示了File::extension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['file' => 'required']);
     $file = $request->file('file');
     $original_file_name = $file->getClientOriginalName();
     $file_name = pathinfo($original_file_name, PATHINFO_FILENAME);
     $extension = \File::extension($original_file_name);
     $actual_name = $file_name . '.' . $extension;
     $apk = new \ApkParser\Parser($file);
     $manifest = $apk->getManifest();
     $labelResourceId = $apk->getManifest()->getApplication()->getLabel();
     $appLabel = $apk->getResources($labelResourceId);
     $package_name = $manifest->getPackageName();
     if (Apk::packageExist($package_name)) {
         Session::flash('flash_class', 'alert-danger');
         Session::flash('flash_message', 'Apk namespace already exist.');
         return redirect()->route("apk.create");
     }
     Apk::create(array('app_name' => $appLabel[0], 'pkgname' => $package_name, 'version' => $manifest->getVersionCode(), 'version_name' => $manifest->getVersionName(), 'md5' => md5_file($file), 'filename' => $actual_name, 'filesize' => str_format_filesize(\File::size($file)), 'token' => md5(uniqid(mt_rand(), true))));
     $folderpath = base_path() . '/storage/apk/' . $manifest->getPackageName();
     if (!\File::exists($folderpath)) {
         \File::makeDirectory($folderpath);
     }
     $file_path = $request->file('file')->move($folderpath, $actual_name);
     return redirect()->route("apk.index");
 }
开发者ID:renciebautista,项目名称:pcount2,代码行数:32,代码来源:ApkController.php

示例2: action_create

 public function action_create()
 {
     $input = Input::all();
     if (isset($input['description'])) {
         $input['description'] = filter_var($input['description'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     }
     $rules = array('image' => 'required|image|max:200', 'description' => 'required', 'name' => 'required');
     $messages = array('image_required' => 'Please select an image for upload!', 'image_max' => 'Make sure image is no larger than 500kb', 'image_image' => 'Please select an image file');
     $validation = Validator::make($input, $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('admin/gallery/new')->with_errors($validation);
     }
     $extension = File::extension($input['image']['name']);
     $directory = path('public') . 'uploads/' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id . time()) . ".{$extension}";
     $upload_success = Input::upload('image', $directory, $filename);
     if ($upload_success) {
         $photo = new Image(array('name' => Input::get('name'), 'location' => '/uploads/' . sha1(Auth::user()->id) . '/' . $filename, 'description' => $input['description'], 'type' => $extension));
         Auth::user()->images()->insert($photo);
         Session::flash('status_create', 'Successfully uploaded your new Instapic');
         Session::flash('id', $photo->id);
     } else {
         Log::write('admin.gallery.create', 'Image was not uploaded, $photo->create() returned false.');
         Session::flash('error_create', 'An error occurred while uploading your new Instapic - please try again.');
     }
     return Redirect::to('admin/gallery/new');
 }
开发者ID:ryankennedy1991,项目名称:Toure-cms,代码行数:27,代码来源:gallery.php

示例3: action_create

 public function action_create()
 {
     /*$slug = $this->slugger(Input::get('title'));
     
     		$db = Post::create(array(
     				'post_title' => Input::get('title'),
     				'post_content' => Input::get('content'),
     				'excerpt' => Input::get('excerpt'),
     				'slug' => $slug,
     				'user_id' => Auth::user()->id,
     			));
     		
     		if(!$db){
     			Log::write('posts.create', 'Post was not created, post->create() returned false.');
     			 return Redirect::to('posts/new')
     		                 ->with('error_create', 'Unable to create post!');
     		} */
     $db = Post::find(2);
     $input = Input::all();
     $rules = array('image' => 'required|image|max:200');
     $messages = array('image_required' => 'Please select an image for upload!', 'image_max' => 'Make sure image is no larger than 500kb', 'image_image' => 'Please select an image file');
     $validation = Validator::make($input, $rules, $messages);
     if ($validation->fails()) {
         return Redirect::to('posts/new')->with_errors($validation);
     }
     $extension = File::extension($input['image']['name']);
     $directory = path('public') . 'uploads/' . sha1(Auth::user()->id);
     $filename = sha1(Auth::user()->id . time()) . ".{$extension}";
     $upload_success = Input::upload('image', $directory, $filename);
     if ($upload_success) {
         $photo = new Image(array('image_name' => $filename, 'image_location' => '/uploads/' . sha1(Auth::user()->id) . '/' . $filename, 'image_size' => $input['image']['size'], 'image_type' => $extension));
         $db->images()->insert($photo);
     }
     return Redirect::to('posts/new')->with('status_create', 'New Post Created')->with('id', $db->id);
 }
开发者ID:ryankennedy1991,项目名称:makeitvalue,代码行数:35,代码来源:posts.php

示例4: upload

 /**
  * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed
  * @param  string  $field             The name of the $_FILES field you want to upload
  * @param  boolean $upload_type       The type of upload ('news', 'gallery', 'section') etc
  * @param  boolean $type_id           The ID of the item (above) that the upload is linked to
  * @param  boolean $remove_existing   Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new one is uploaded for example)
  * @return object                     Returns the upload object so we can work with the uploaded file and details
  */
 public static function upload($field = 'image', $upload_type = false, $type_id = false, $remove_existing = false)
 {
     if (!$field || !$upload_type || !$type_id) {
         return false;
     }
     $input = Input::file($field);
     if ($input && $input['error'] == UPLOAD_ERR_OK) {
         if ($remove_existing) {
             static::remove($upload_type, $type_id);
         }
         $ext = File::extension($input['name']);
         $filename = Str::slug(Input::get('title'), '-');
         Input::upload('image', './uploads/' . $filename . '.' . $ext);
         $upload = new Upload();
         $upload->link_type = $upload_type;
         $upload->link_id = $type_id;
         $upload->filename = $filename . '.' . $ext;
         if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) {
             $upload->small_filename = $filename . '_small' . '.' . $ext;
             $upload->thumb_filename = $filename . '_thumb' . '.' . $ext;
             $upload->image = 1;
         }
         $upload->extension = $ext;
         $upload->user_id = Auth::user()->id;
         $upload->save();
         return $upload;
     }
 }
开发者ID:victoroliveira1605,项目名称:Laravel-Bootstrap,代码行数:36,代码来源:uploadr.php

示例5: scan

 public function scan($recursive = true, $dir = '', &$list = [])
 {
     $dir = $dir ?: $this->path;
     if ($handle = opendir($dir)) {
         $this->exclude = empty($this->exclude) ? ['extension' => [], 'file' => [], 'dir' => []] : $this->exclude;
         while (($file = readdir($handle)) !== false) {
             $extension = File::extension($file);
             if ($file == '.' || $file == '..' || in_array($extension, $this->exclude['extension'])) {
                 continue;
             }
             $path = $dir . DIRECTORY_SEPARATOR . $file;
             if (is_readable($path)) {
                 if (is_dir($path) && !in_array($file, $this->exclude['dir'])) {
                     $list[] = ['name' => $file, 'type' => 'directory', 'path' => $path];
                     if ($recursive) {
                         $this->scan($recursive, $path, $list);
                     }
                 } elseif (is_file($path) && !in_array($file, $this->exclude['file'])) {
                     $list[] = ['name' => $file, 'extension' => $extension, 'type' => 'file', 'path' => $path];
                 }
             }
         }
         closedir($handle);
     }
     return array_map('array_filter', $list);
 }
开发者ID:ncaneldiee,项目名称:sampadeh,代码行数:26,代码来源:Filesystem.php

示例6: post_upload

 public function post_upload()
 {
     $input = Input::get();
     $file = Input::file('fileInput');
     $separator = $input['claimdetailid'] != NULL ? $input['claimid'] . '/' . $input['claimdetailid'] : $input['claimid'];
     $extension = File::extension($file['name']);
     $directory = 'upload/claims/' . sha1(Auth::user()->userid) . '/' . str_replace("-", "", date('Y-m-d')) . '/' . $separator;
     $filename = Str::random(16, 'alpha') . time() . ".{$extension}";
     if (!is_dir(path('public') . $directory)) {
         mkdir(path('public') . $directory, 0777, true);
     }
     $maxSize = ini_get('upload_max_filesize') * 1024 * 1024 * 1024;
     if ($file['size'] != null && $file['size'] < $maxSize) {
         try {
             $upload_success = Input::upload('fileInput', path('public') . $directory, $filename);
             if ($upload_success) {
                 $input['recpath'] = $directory . '/' . $filename;
                 $receipt = new Claims_Receipt();
                 $receipt->fill($input);
                 $receipt->save();
                 Log::write('Claims Receipt', 'File Uploaded : ' . $filename . ' by ' . Auth::user()->username);
                 return $directory . '/' . $filename;
             }
         } catch (Exception $e) {
             Log::write('Claims Receipt', 'Upload error: ' . $e->getMessage());
         }
     } else {
         Log::write('Claims Receipt', 'Upload error: Exceed max size ' . ini_get('upload_max_filesize'));
     }
 }
开发者ID:farhan4648gul,项目名称:developer-side,代码行数:30,代码来源:request.php

示例7: post_new

 public function post_new()
 {
     $input = Input::all();
     //grab our input
     $rules = array('name' => 'required|alpha', 'lastName' => 'required|alpha', 'permit' => 'required|min:2', 'lot' => 'required|integer', 'msc' => 'integer', 'ticket' => 'required|min:2|numeric|unique:tickets,ticketID', 'fineAmt' => 'required|numeric', 'licensePlate' => 'required|alpha_num', 'licensePlateState' => 'required|max:2', 'dateIssued' => 'required', 'violations' => 'required', 'areaOfViolation' => 'required|alpha_num', 'appealLetter' => 'required|max:700');
     //validation rules
     $validation = Validator::make($input, $rules);
     //let's run the validator
     if ($validation->fails()) {
         return Redirect::to('appeal/new')->with_errors($validation);
     }
     //hashing the name of the file uploaded for security sake
     //then we'll be dropping it into the public/uploads file
     //get the file extension
     $extension = File::extension($input['appealLetter']['name']);
     //encrypt the file name
     $file = Crypter::encrypt($input['appealLetter']['name'] . time());
     //for when the crypter likes to put slashes in our scrambled filname
     $file = preg_replace('#/+#', '', $file);
     //concatenate extension and filename
     $filename = $file . "." . $extension;
     Input::upload('appealLetter', path('public') . 'uploads/', $filename);
     //format the fine amount in case someone screws it up
     $fineamt = number_format(Input::get('fineAmt'), 2, '.', '');
     //inserts the form data into the database assuming we pass validation
     Appeal::create(array('name' => Input::get('name'), 'lastName' => Input::get('lastName'), 'permitNumber' => Input::get('permit'), 'assignedLot' => Input::get('lot'), 'MSC' => Input::get('msc'), 'ticketID' => Input::get('ticket'), 'fineAmt' => $fineamt, 'licensePlate' => Str::upper(Input::get('licensePlate')), 'licensePlateState' => Input::get('licensePlateState'), 'dateIssued' => date('Y-m-d', strtotime(Input::get('dateIssued'))), 'violations' => Input::get('violations'), 'areaOfViolation' => Input::get('areaOfViolation'), 'letterlocation' => URL::to('uploads/' . $filename), 'CWID' => Session::get('cwid')));
     return Redirect::to('appeal/')->with('alertMessage', 'Appeal submitted successfully.');
 }
开发者ID:nkwsy,项目名称:ParkingAppeal,代码行数:28,代码来源:appeal.php

示例8: setImageAttribute

 /**
  * Upload the image while creating/updating records
  * @param File Object $file
  */
 public function setImageAttribute($file)
 {
     // Only if a file is selected
     if ($file) {
         File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/');
         File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
         File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
         $file_name = $file->getClientOriginalName();
         $file_ext = File::extension($file_name);
         $only_fname = str_replace('.' . $file_ext, '', $file_name);
         $file_name = $only_fname . '_' . str_random(8) . '.' . $file_ext;
         $image = Image::make($file->getRealPath());
         if (isset($this->attributes['folder'])) {
             // $this->attributes['folder'] = Str::slug($this->attributes['folder'], '_');
             $this->images_path = $this->attributes['folder'] . '/';
             $this->thumbs_path = $this->images_path . '/thumbs/';
             File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
             File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
         }
         if (isset($this->attributes['image'])) {
             // Delete old image
             $old_image = $this->getImageAttribute();
             File::exists($old_image) && File::delete($old_image);
         }
         if (isset($this->attributes['thumbnail'])) {
             // Delete old thumbnail
             $old_thumb = $this->getThumbnailAttribute();
             File::exists($old_thumb) && File::delete($old_thumb);
         }
         $image->save(public_path($this->images_path . $file_name))->fit(150, 150)->save(public_path($this->thumbs_path . $file_name));
         $this->attributes['image'] = "{$this->attributes['folder']}/{$file_name}";
         $this->attributes['thumbnail'] = "{$this->attributes['folder']}/thumbs/{$file_name}";
         unset($this->attributes['folder']);
     }
 }
开发者ID:doptor,项目名称:doptor,代码行数:39,代码来源:MediaEntry.php

示例9: upload

 public static function upload($model, $modelName, $name, $attribute, $removePastImage = true, $sizes = array())
 {
     $uploadOptions = $attribute["uploadOptions"];
     $path = "public";
     $beforeImage = $model->{$name};
     if (isset($uploadOptions["sizes"])) {
         $sizes = $uploadOptions["sizes"];
     }
     if (isset($uploadOptions["path"])) {
         $path = $uploadOptions["path"];
     }
     $files = Input::file($name);
     if ($files["name"] == "") {
         return false;
     }
     $extension = File::extension($files["name"]);
     $directory = path($path) . $uploadOptions["directory"];
     $nameFile = sha1(Session::has("token_user") . microtime());
     $filename = "{$nameFile}.{$extension}";
     $fullPath = $directory . "/" . $filename;
     $defaultImage = $directory . "/" . $filename;
     $defaultImageName = $filename;
     $successUpload = Input::upload($name, $directory, $filename);
     if ($successUpload === false) {
         return false;
     }
     if (File::exists($directory . "/" . $beforeImage)) {
         File::delete($directory . "/" . $beforeImage);
     }
     var_dump($beforeImage);
     $beforeExtension = File::extension($beforeImage);
     $preg = $directory . "/" . preg_replace("/\\.{$beforeExtension}/", "", $beforeImage);
     if (!empty($beforeImage)) {
         foreach (glob("{$preg}*", GLOB_ONLYDIR) as $key => $dir) {
             File::rmdir($dir);
         }
     }
     foreach ($sizes as $key => $size) {
         if (!preg_match("/\\d*x\\d*/", $size)) {
             throw new Exception("Size doesnt have a valid format valid for {$size} example: ddxdd", 1);
         }
         if (!class_exists("Resizer")) {
             throw new Exception("Bundle Resizer must be installed <br> Please got to <a href='http://bundles.laravel.com/bundle/resizer'>http://bundles.laravel.com/bundle/resizer</a>", 1);
         }
         $filename = $nameFile . "_{$key}.{$extension}";
         $sizeOptions = preg_split("/x/", $size);
         $fullPath = $directory . "/{$nameFile}{$key}/" . $filename;
         $beforeImageWithSize = $directory . "/{$nameFile}{$key}/" . $beforeImage;
         if (!is_dir($directory . "/" . $nameFile . $key)) {
             mkdir($directory . "/" . $nameFile . $key, 0777);
         }
         $success = Resizer::open($defaultImage)->resize($sizeOptions[0], $sizeOptions[1], 'fit')->save($fullPath, 90);
         if ($success === false) {
             return false;
         }
     }
     return array("fullPath" => $defaultImage, "fileName" => $defaultImageName);
 }
开发者ID:robriggen,项目名称:lara_admin,代码行数:58,代码来源:filehelper.php

示例10: info

 /**
  * @return string
  */
 public function info() : string
 {
     if ($filename = $this->resolvePath()) {
         list($width, $height) = getimagesize($filename);
         return strtr(static::TEMPLATE_INFO, [':type' => \File::extension($filename), ':width' => $width, ':height' => $height]);
     } else {
         return '';
     }
 }
开发者ID:nightdiraven,项目名称:amari,代码行数:12,代码来源:Image.php

示例11: postStore

 public function postStore()
 {
     $id = \Input::get('id');
     /*
      * Validate
      */
     $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required|unique:categories,name' . (isset($id) ? ',' . $id : ''), 'short_description' => 'required', 'order' => 'required|min:0');
     $validation = \Validator::make(\Input::all(), $rules);
     if ($validation->passes()) {
         $name = \Input::get('name');
         $short_description = \Input::get('short_description');
         $long_description = \Input::get('long_description');
         $image = \Input::file('image');
         $active = \Input::get('active') == '' ? FALSE : TRUE;
         $order = \Input::get('order');
         $parent_id = \Input::get('parent_id');
         $cn_name = \Input::get('cn_name');
         $cn_short_description = \Input::get('cn_short_description');
         $cn_long_description = \Input::get('cn_long_description');
         $options = array('name' => $cn_name, 'short_description' => $cn_short_description, 'long_description' => $cn_long_description);
         $category = isset($id) ? Category::find($id) : new Category();
         $category->name = $name;
         $category->short_description = $short_description;
         $category->long_description = $long_description;
         $category->active = $active;
         $category->order = $order;
         $category->category_id = $parent_id;
         $category->options = json_encode($options);
         $category->save();
         if (\Input::hasFile('image')) {
             // Delete all existing images for edit
             if (isset($id)) {
                 $category->deleteAllImages();
             }
             //set the name of the file
             $originalFilename = $image->getClientOriginalName();
             $filename = str_replace(' ', '', $name) . \Str::random(20) . '.' . \File::extension($originalFilename);
             //Upload the file
             $isSuccess = $image->move('assets/img/categories', $filename);
             if ($isSuccess) {
                 // create photo
                 $newimage = new Image();
                 $newimage->path = $filename;
                 // save photo to the loaded model
                 $category->images()->save($newimage);
             }
         }
     } else {
         if (isset($id)) {
             return \Redirect::to('admin/categories/edit/' . $id)->withErrors($validation)->withInput();
         } else {
             return \Redirect::to('admin/categories/create')->withErrors($validation)->withInput();
         }
     }
     return \Redirect::to('admin/categories');
 }
开发者ID:tusharvikky,项目名称:redminportal,代码行数:56,代码来源:CategoryController.php

示例12: assets

 public function assets($file = null)
 {
     if (!is_null($file) && \File::isDirectory($this->themesAssetsPath)) {
         if (!\File::exists($this->themesAssetsPath . $file)) {
             return \Response::make("Not found!", 404);
         }
         $requestedFile = \File::get($this->themesAssetsPath . $file);
         return \Response::make($requestedFile, 200, array('Content-Type' => $this->mimeMap[\Str::lower(\File::extension($this->themesAssetsPath . $file))]));
     }
     return \Redirect::route('app.home');
 }
开发者ID:adis-me,项目名称:pageblok,代码行数:11,代码来源:AssetController.php

示例13: fileExistFormatImage

 public function fileExistFormatImage($path, $width)
 {
     $url = getcwd() . $path;
     $add = '';
     $ext = array('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF');
     if (\File::exists($url)) {
         $extension = \File::extension($url);
         if (in_array($extension, $ext)) {
             $asset = asset($path);
             return '<img src="' . $asset . '" alt="" width="' . $width . 'px" />';
         }
     }
 }
开发者ID:abada,项目名称:webshop,代码行数:13,代码来源:Format.php

示例14: getFileTypeAttribute

 public function getFileTypeAttribute()
 {
     $extension = File::extension($this->url);
     if ($extension == 'png' || $extension == 'jpg' || $extension == 'bmp') {
         return 'image';
     } elseif ($extension == 'mp4') {
         return 'video';
     } elseif ($extension == 'pdf') {
         return 'pdf';
     } elseif ($extension == '' || $extension == 'com') {
         return 'link';
     }
     return 'other';
 }
开发者ID:andrestntx,项目名称:Education,代码行数:14,代码来源:Link.php

示例15: makeFileName

 /**
  * 生成文件名
  * @param $file UploadedFile|SplFileInfo|string
  * @return string
  */
 public function makeFileName($file)
 {
     if (is_a($file, UploadedFile::class)) {
         $filename = date('Y-m-d-') . md5(md5_file($file->getRealPath()) . time()) . '.' . $file->getClientOriginalExtension();
     } elseif (is_a($file, SplFileInfo::class)) {
         $filename = date('Y-m-d-') . md5(md5_file($file->getRealPath()) . time()) . '.' . $file->getExtension();
     } elseif (is_string($file)) {
         $extension = \File::extension($file);
         $filename = date('Y-m-d-') . md5($file . time()) . '.' . $extension;
     } else {
         throw new \RuntimeException(__METHOD__ . ' needs a UploadedFile|SplFileInfo|string instance or a file path string');
     }
     return $filename;
 }
开发者ID:jiangtong1125,项目名称:laravel-upload-manager,代码行数:19,代码来源:UploadStrategy.php


注:本文中的File::extension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。