本文整理匯總了PHP中Illuminate\Support\Facades\File::extension方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::extension方法的具體用法?PHP File::extension怎麽用?PHP File::extension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\File
的用法示例。
在下文中一共展示了File::extension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getRename
/**
* @return string
*/
public function getRename()
{
$old_name = Input::get('file');
$new_name = Input::get('new_name');
$file_path = parent::getPath('directory');
$thumb_path = parent::getPath('thumb');
$old_file = $file_path . $old_name;
if (!File::isDirectory($old_file)) {
$extension = File::extension($old_file);
$new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension;
}
$new_file = $file_path . $new_name;
if (File::exists($new_file)) {
return Lang::get('laravel-filemanager::lfm.error-rename');
}
if (File::isDirectory($old_file)) {
File::move($old_file, $new_file);
return 'OK';
}
File::move($old_file, $new_file);
if ('Images' === $this->file_type) {
File::move($thumb_path . $old_name, $thumb_path . $new_name);
}
return 'OK';
}
示例2: getRename
/**
* @return string
*/
public function getRename()
{
$old_name = Input::get('file');
$new_name = trim(Input::get('new_name'));
$file_path = parent::getPath('directory');
$thumb_path = parent::getPath('thumb');
$old_file = $file_path . $old_name;
if (!File::isDirectory($old_file)) {
$extension = File::extension($old_file);
$new_name = str_replace('.' . $extension, '', $new_name) . '.' . $extension;
}
$new_file = $file_path . $new_name;
if (Config::get('lfm.alphanumeric_directory') && preg_match('/[^\\w-]/i', $new_name)) {
return Lang::get('laravel-filemanager::lfm.error-folder-alnum');
} elseif (File::exists($new_file)) {
return Lang::get('laravel-filemanager::lfm.error-rename');
}
if (File::isDirectory($old_file)) {
File::move($old_file, $new_file);
Event::fire(new FolderWasRenamed($old_file, $new_file));
return 'OK';
}
File::move($old_file, $new_file);
if ('Images' === $this->file_type) {
File::move($thumb_path . $old_name, $thumb_path . $new_name);
}
Event::fire(new ImageWasRenamed($old_file, $new_file));
return 'OK';
}
示例3: getFileInfos
private function getFileInfos($files, $type = 'Images')
{
$file_info = [];
foreach ($files as $key => $file) {
$file_name = parent::getFileName($file)['short'];
$file_created = filemtime($file);
$file_size = number_format(File::size($file) / 1024, 2, ".", "");
if ($file_size > 1024) {
$file_size = number_format($file_size / 1024, 2, ".", "") . " Mb";
} else {
$file_size = $file_size . " Kb";
}
if ($type === 'Images') {
$file_type = File::mimeType($file);
$icon = '';
} else {
$extension = strtolower(File::extension($file_name));
$icon_array = Config::get('lfm.file_icon_array');
$type_array = Config::get('lfm.file_type_array');
if (array_key_exists($extension, $icon_array)) {
$icon = $icon_array[$extension];
$file_type = $type_array[$extension];
} else {
$icon = "fa-file";
$file_type = "File";
}
}
$file_info[$key] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'icon' => $icon];
}
return $file_info;
}
示例4: store
public static function store($files, $material)
{
// Making counting of uploaded images
$file_count = count($files);
// start count how many uploaded
$uploadcount = 0;
if (!empty($files)) {
foreach ($files as $file_path) {
if (!empty($file_path)) {
$type = File::type($file_path);
$mime = File::mimeType($file_path);
$extension = File::extension($file_path);
$filename = $material->slug . '_' . str_replace(' ', '_', File::name($file_path)) . '.' . $extension;
File::move($file_path, storage_path() . '/app/' . $filename);
//add file path and thumb path to material_files database
$material_file = MaterialFile::firstOrCreate(['original_filename' => File::name($file_path), 'filename' => $filename, 'mime' => $mime]);
//add to material file table
$material->files()->save($material_file);
$uploadcount++;
//create thumb
MaterialFile::makeThumb($extension, $filename);
}
}
if ($uploadcount == $file_count) {
Session::flash('success', 'Upload(s) successfully');
} else {
return Redirect::to('material.edit')->withInput();
}
}
}
示例5: postStore
public function postStore()
{
$id = Input::get('id');
/*
* Validate
*/
$rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'name' => 'required', 'short_description' => 'required', 'long_description' => 'required', 'start_date' => 'required', 'end_date' => 'required');
$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;
$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);
$start_date = DateTime::createFromFormat('d/m/Y', Input::get('start_date'));
$end_date = DateTime::createFromFormat('d/m/Y', Input::get('end_date'));
$promotion = isset($id) ? Promotion::find($id) : new Promotion();
$promotion->name = $name;
$promotion->start_date = $start_date;
$promotion->end_date = $end_date;
$promotion->short_description = $short_description;
$promotion->long_description = $long_description;
$promotion->active = $active;
$promotion->options = json_encode($options);
$promotion->save();
if (Input::hasFile('image')) {
// Delete all existing images for edit
if (isset($id)) {
$promotion->deleteAllImages();
}
//set the name of the file
$originalFilename = $image->getClientOriginalName();
$filename = 'promo' . date("dmY") . '_' . Str::random(20) . '.' . File::extension($originalFilename);
//Upload the file
$isSuccess = $image->move('assets/img/promotions', $filename);
if ($isSuccess) {
// create photo
$newimage = new Image();
$newimage->path = $filename;
// save photo to the loaded model
$promotion->images()->save($newimage);
}
}
} else {
if (isset($id)) {
return Redirect::to('admin/promotions/edit/' . $id)->withErrors($validation)->withInput();
} else {
return Redirect::to('admin/promotions/create')->withErrors($validation)->withInput();
}
}
return Redirect::to('admin/promotions');
}
示例6: show
/**
* Display the specified resource.
*
* @param string $name
* @return Response
*/
public function show($name)
{
$project = Project::where('name', $name)->get()->first();
$x = new Filesystem();
$filesDestination = File::allfiles($_SERVER['DOCUMENT_ROOT'] . '/uploads/' . $name);
$files = array();
for ($c = 0; $c < count($filesDestination); $c++) {
$files[$c] = File::name($filesDestination[$c]) . '.' . File::extension($filesDestination[$c]);
}
//dd($filenames);
return view('project.show', compact('project', 'files'));
}
示例7: setHeader
/**
* * Set proper header to serve the video content
* */
private function setHeader()
{
ob_get_clean();
$extension = File::extension($this->path);
if ($extension == 'ogg') {
header("Content-Type: application/ogg");
} else {
header("Content-Type: application/octet-stream");
}
//header("Content-Type: application/octet-stream");
header("Cache-Control: max-age=2592000, public");
header("Expires: " . gmdate('D, d M Y H:i:s', time() + 2592000) . ' GMT');
header("Last-Modified: " . gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT');
$this->start = 0;
$this->size = filesize($this->path);
$this->end = $this->size - 1;
header("Accept-Ranges: 0-" . $this->end);
if (isset($_SERVER['HTTP_RANGE'])) {
$c_start = $this->start;
$c_end = $this->end;
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes {$this->start}-{$this->end}/{$this->size}");
exit;
}
if ($range == '-') {
$c_start = $this->size - substr($range, 1);
} else {
$range = explode('-', $range);
$c_start = $range[0];
$c_end = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $c_end;
}
$c_end = $c_end > $this->end ? $this->end : $c_end;
if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes {$this->start}-{$this->end}/{$this->size}");
exit;
}
$this->start = $c_start;
$this->end = $c_end;
$length = $this->end - $this->start + 1;
fseek($this->stream, $this->start);
header('HTTP/1.1 206 Partial Content');
header("Content-Length: " . $length);
header("Content-Range: bytes {$this->start}-{$this->end}/" . $this->size);
} else {
header("Content-Length: " . $this->size);
}
}
示例8: get
static function get($img, $w = "", $h = "", $crop = true, $params = array())
{
$fullPath = public_path() . '/' . $img;
if (!File::exists($fullPath)) {
return false;
}
$format = '';
$width = '';
$htmlWidth = '';
$height = '';
$htmlHeight = '';
$filter = "";
$method = '';
$lazyParams = '';
$ext = File::extension($fullPath);
if ($ext == 'png') {
$firstBytes = @file_get_contents($fullPath, false, null, 25, 1);
if (ord($firstBytes) & 4) {
$format = "f=png";
//for transparent pngs
}
}
if ($w) {
$width = 'w=' . $w;
$htmlWidth = 'width="' . $w . '"';
}
if ($h) {
$height = 'h=' . $h;
$htmlHeight = 'height="' . $h . '"';
}
if (count($params) > 0) {
$filter = implode('&', $params);
//eg: fltr[]=gray
}
if ($w != "" && $h != "") {
if ($crop) {
$method = 'zc=1';
} else {
$method = 'far=1&bg=FFFFFF';
}
}
$image = 'src=' . $img;
$optionsSlices = array($method, $width, $height, $filter, $image, $format);
$options = implode('&', array_filter($optionsSlices));
$src = Url::to('/phpthumb') . "?" . $options;
$htmlOptionsSlices = array($htmlWidth, $htmlHeight, $lazyParams);
$htmlOptions = implode(' ', array_filter($htmlOptionsSlices));
return '<img src="' . $src . '" ' . $htmlOptions . ' />';
}
示例9: getRename
/**
* @return string
*/
public function getRename()
{
$file_to_rename = Input::get('file');
$dir = Input::get('dir');
$new_name = Str::slug(Input::get('new_name'));
if ($dir == "/") {
if (File::exists(base_path() . "/" . $this->file_location . $new_name)) {
return "File name already in use!";
} else {
if (File::isDirectory(base_path() . "/" . $this->file_location . $file_to_rename)) {
File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name);
return "OK";
} else {
$extension = File::extension(base_path() . "/" . $this->file_location . $file_to_rename);
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
File::move(base_path() . "/" . $this->file_location . $file_to_rename, base_path() . "/" . $this->file_location . $new_name);
if (Session::get('lfm_type') == "Images") {
// rename thumbnail
File::move(base_path() . "/" . $this->file_location . "thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . "thumbs/" . $new_name);
}
return "OK";
}
}
} else {
if (File::exists(base_path() . "/" . $this->file_location . $dir . "/" . $new_name)) {
return "File name already in use!";
} else {
if (File::isDirectory(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename)) {
File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name);
} else {
$extension = File::extension(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename);
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
File::move(base_path() . "/" . $this->file_location . $dir . "/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/" . $new_name);
if (Session::get('lfm_type') == "Images") {
File::move(base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $file_to_rename, base_path() . "/" . $this->file_location . $dir . "/thumbs/" . $new_name);
}
return "OK";
}
}
}
return true;
}
示例10: getRename
/**
* @return string
*/
function getRename()
{
$file_to_rename = Input::get('file');
$dir = Input::get('dir');
$new_name = Str::slug(Input::get('new_name'));
if ($dir == "/") {
if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $new_name)) {
return Lang::get('filemanager::sfm.file_exists');
} else {
if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) {
File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name);
return "OK";
} else {
$extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename);
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename)) {
// rename thumbnail
File::move(base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . "/.thumbs/" . $new_name);
}
File::move(base_path() . "/" . Config::get('sfm.dir') . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $new_name);
return "OK";
}
}
} else {
if (File::exists(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name)) {
return Lang::get('filemanager::sfm.file_exists');
} else {
if (File::isDirectory(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) {
File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name);
} else {
$extension = File::extension(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename);
$new_name = Str::slug(str_replace($extension, '', $new_name)) . "." . $extension;
if (@getimagesize(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename)) {
File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/.thumbs/" . $new_name);
}
File::move(base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $file_to_rename, base_path() . "/" . Config::get('sfm.dir') . $dir . "/" . $new_name);
return "OK";
}
}
}
}
示例11: getFiles
/**
* Return json list of files
*
* @return mixed
*/
public function getFiles()
{
if (Input::has('base')) {
$files = File::files(base_path($this->file_location . Input::get('base')));
$all_directories = File::directories(base_path($this->file_location . Input::get('base')));
} else {
$files = File::files(base_path($this->file_location));
$all_directories = File::directories(base_path($this->file_location));
}
$directories = [];
foreach ($all_directories as $directory) {
$directories[] = basename($directory);
}
$file_info = [];
$icon_array = Config::get('lfm.file_icon_array');
$type_array = Config::get('lfm.file_type_array');
foreach ($files as $file) {
$file_name = $file;
$file_size = 1;
$extension = strtolower(File::extension($file_name));
if (array_key_exists($extension, $icon_array)) {
$icon = $icon_array[$extension];
$type = $type_array[$extension];
} else {
$icon = "fa-file";
$type = "File";
}
$file_created = filemtime($file);
$file_type = '';
$file_info[] = ['name' => $file_name, 'size' => $file_size, 'created' => $file_created, 'type' => $file_type, 'extension' => $extension, 'icon' => $icon, 'type' => $type];
}
if (Input::get('show_list') == 1) {
return View::make('laravel-filemanager::files-list')->with('directories', $directories)->with('base', Input::get('base'))->with('file_info', $file_info)->with('dir_location', $this->file_location);
} else {
return View::make('laravel-filemanager::files')->with('files', $files)->with('directories', $directories)->with('base', Input::get('base'))->with('file_info', $file_info)->with('dir_location', $this->file_location);
}
}
示例12: scanFiles
/**
* Scan files of the given directory.
*
* @param $current_directory
* @return \Illuminate\Support\Collection
*/
protected function scanFiles($current_directory)
{
$files = collect($this->storage->files($current_directory));
$files = $files->filter(function ($file) {
$ext = File::extension($file);
if ($this->filter === 'images') {
return in_array($ext, $this->config->get('media.images_ext'));
} elseif ($this->filter === 'files') {
return in_array($ext, $this->config->get('media.files_ext'));
}
return true;
});
return $files;
}
示例13: function
<?php
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Swagger\Swagger;
$app->get(config('swagger-lume.routes.docs'), function ($page = 'api-docs.json') {
$filePath = config('swagger-lume.paths.docs') . "/{$page}";
if (File::extension($filePath) === '') {
$filePath .= '.json';
}
if (!File::exists($filePath)) {
App::abort(404, "Cannot find {$filePath}");
}
$content = File::get($filePath);
return new Response($content, 200, ['Content-Type' => 'application/json']);
});
$app->get(config('swagger-lume.routes.api'), function () {
if (config('swagger-lume.generate_always')) {
\SwaggerLume\Generator::generateDocs();
}
if (config('swagger-lume.proxy')) {
$proxy = (new Request())->server('REMOTE_ADDR');
(new Request())->setTrustedProxies([$proxy]);
}
$extras = [];
$conf = config('swagger-lume');
if (array_key_exists('validatorUrl', $conf)) {
// This allows for a null value, since this has potentially
// desirable side effects for swagger. See the view for more
示例14: extension
/**
* Return the type of the resource
*
* @param string $path
*/
public function extension($path)
{
return File::extension($this->getPath($path));
}
示例15: download
public function download(Fileentry $entry)
{
$extension = File::extension($entry->link);
$password = file_get_contents('../filepassword');
Request::get('pass');
if ($password == Request::get('pass')) {
if (!Auth::user()) {
$entry->increment('views');
}
return response()->download($entry->link, $entry->title . '.' . $extension);
} else {
return redirect("documents")->withErrors(['pnm' => ""]);
}
}