本文整理匯總了PHP中Illuminate\Support\Facades\File::size方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::size方法的具體用法?PHP File::size怎麽用?PHP File::size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Illuminate\Support\Facades\File
的用法示例。
在下文中一共展示了File::size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: user
public function user()
{
if (Session::get('isLogged') == true) {
$path = storage_path() . '\\upload\\' . Session::get('index');
$files = array_diff(scandir($path), array('.', '..'));
$parse = array();
foreach ($files as $k => $v) {
// име на фајл
$array = array();
array_push($array, $v);
// големина на фајл
$path = storage_path() . '\\upload\\' . Session::get('index') . '\\' . $v;
$bytes = File::size($path);
$bytes = self::formatSizeUnits($bytes);
array_push($array, $bytes);
// пат до фајлот
array_push($array, $path);
// array-от кој се испраќа на view
array_push($parse, $array);
}
$data = array('files' => $parse);
return View::make('user')->with($data);
} else {
abort(404);
}
}
示例3: saveFile
/**
* Saves File.
*
* @param string $fileName File input name
* @param string $location Storage location
*
* @return array
*/
public static function saveFile($fileName, $directory = '', $fileTypes = [])
{
if (is_object($fileName)) {
$file = $fileName;
$originalName = $file->getClientOriginalName();
} else {
$file = Request::file($fileName);
$originalName = false;
}
if (is_null($file)) {
return false;
}
if (File::size($file) > Config::get('quarx.maxFileUploadSize', '')) {
throw new Exception('This file is too large', 1);
}
if (substr($directory, 0, -1) != '/') {
$directory .= '/';
}
$extension = $file->getClientOriginalExtension();
$newFileName = md5(rand(1111, 9999) . time());
// In case we don't want that file type
if (!empty($fileTypes)) {
if (!in_array($extension, $fileTypes)) {
throw new Exception('Incorrect file type', 1);
}
}
Storage::disk(Config::get('quarx.storage-location', 'local'))->put($directory . $newFileName . '.' . $extension, File::get($file));
return ['original' => $originalName ?: $file->getFilename() . '.' . $extension, 'name' => $directory . $newFileName . '.' . $extension];
}
示例4: getServerImages
public function getServerImages()
{
$images = Image::get(['original_name', 'filename']);
$imageAnswer = [];
foreach ($images as $image) {
$imageAnswer[] = ['original' => $image->original_name, 'server' => $image->filename, 'size' => File::size(public_path('images/full_size/' . $image->filename))];
}
// http://laravel-image-upload-dropzone.local/public/images/full_size/v1-c26b3.png
// 'size' => File::size(public_path('images/full_size/' . $image->filename))
return response()->json(['images' => $imageAnswer]);
}
示例5: transform
/**
* Transform the source file.
*
* @param \CipeMotion\Medialibrary\Entities\File $file
*
* @return \CipeMotion\Medialibrary\Entities\Transformation
*/
public function transform(File $file)
{
// Get a temp path to work with
$destination = get_temp_path();
// Get a Image instance from the file
$image = Image::make($file->getLocalPath($destination));
// Resize either with the fit strategy or just force the resize to the size
if (array_get($this->config, 'fit', false)) {
$image->fit(array_get($this->config, 'size.w', null), array_get($this->config, 'size.h', null), function (Constraint $constraint) {
if (!array_get($this->config, 'upsize', true)) {
$constraint->upsize();
}
});
} else {
$image->resize(array_get($this->config, 'size.w', null), array_get($this->config, 'size.h', null), function (Constraint $constraint) {
if (array_get($this->config, 'aspect', true)) {
$constraint->aspectRatio();
}
if (!array_get($this->config, 'upsize', true)) {
$constraint->upsize();
}
});
}
// Save the image to the temp path
$image->save($destination);
// Setup the transformation properties
$transformation = new Transformation();
$transformation->name = $this->name;
$transformation->type = $file->type;
$transformation->size = Filesystem::size($destination);
$transformation->width = $image->width();
$transformation->height = $image->height();
$transformation->mime_type = $file->mime_type;
$transformation->extension = $file->extension;
$transformation->completed = true;
// Get the disk and a stream from the cropped image location
$disk = Storage::disk($file->disk);
$stream = fopen($destination, 'r+');
// Either overwrite the original uploaded file or write to the transformation path
if (array_get($this->config, 'default', false)) {
$disk->put("{$file->id}/upload.{$transformation->extension}", $stream);
} else {
$disk->put("{$file->id}/{$transformation->name}.{$transformation->extension}", $stream);
}
// Close the stream again
if (is_resource($stream)) {
fclose($stream);
}
// Return the transformation
return $transformation;
}
示例6: getFileSize
public function getFileSize($human = true)
{
$size = File::size($this->generateLocalPath());
if ($human) {
if ($size < 1024) {
return $size . ' bytes';
} elseif ($size < pow(1024, 2)) {
return round($size / pow(1024, 1), 1) . ' kilobytes';
} elseif ($size < pow(1024, 3)) {
return round($size / pow(1024, 2), 1) . ' megabytes';
} else {
return round($size / pow(1024, 3), 1) . ' gigabytes';
}
} else {
return $size;
}
}
示例7: all
/**
* @return array
*/
public static function all()
{
$log = array();
$log_levels = self::getLogLevels();
$pattern = '/\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\].*/';
if (!self::$file) {
$log_file = self::getFiles();
if (!count($log_file)) {
return [];
}
self::$file = $log_file[0];
}
if (File::size(self::$file) > self::MAX_FILE_SIZE) {
return null;
}
$file = File::get(self::$file);
preg_match_all($pattern, $file, $headings);
if (!is_array($headings)) {
return $log;
}
$log_data = preg_split($pattern, $file);
if ($log_data[0] < 1) {
array_shift($log_data);
}
foreach ($headings as $h) {
for ($i = 0, $j = count($h); $i < $j; $i++) {
foreach ($log_levels as $level_key => $level_value) {
if (strpos(strtolower($h[$i]), '.' . $level_value)) {
preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*?\\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
if (!isset($current[2])) {
continue;
}
$log[] = array('level' => $level_value, 'level_class' => self::$levels_classes[$level_value], 'level_img' => self::$levels_imgs[$level_value], 'date' => $current[1], 'text' => $current[2], 'in_file' => isset($current[3]) ? $current[3] : null, 'stack' => preg_replace("/^\n*/", '', $log_data[$i]));
}
}
}
}
return array_reverse($log);
}
示例8: preview
/**
* Previews a log file.
*
* TODO: make it work no matter the flysystem driver (S3 Bucket, etc).
*/
public function preview($file_name)
{
if (!\Entrust::can('preview-logs')) {
abort(403, 'Unauthorized access - you do not have the necessary permission to preview logs.');
}
$disk = Storage::disk('storage');
if ($disk->exists('logs/' . $file_name)) {
self::$file = storage_path() . '/logs/' . $file_name;
$log = array();
$log_levels = self::getLogLevels();
$pattern = '/\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\].*/';
if (!self::$file) {
$log_file = self::getFiles();
if (!count($log_file)) {
return [];
}
self::$file = $log_file[0];
}
if (File::size(self::$file) > self::MAX_FILE_SIZE) {
return null;
}
$file = File::get(self::$file);
preg_match_all($pattern, $file, $headings);
if (!is_array($headings)) {
return $log;
}
$log_data = preg_split($pattern, $file);
if ($log_data[0] < 1) {
array_shift($log_data);
}
foreach ($headings as $h) {
for ($i = 0, $j = count($h); $i < $j; $i++) {
foreach ($log_levels as $level_key => $level_value) {
if (strpos(strtolower($h[$i]), '.' . $level_value)) {
preg_match('/^\\[(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2})\\].*?\\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
if (!isset($current[2])) {
continue;
}
$log[] = array('level' => $level_value, 'level_class' => self::$levels_classes[$level_value], 'level_img' => self::$levels_imgs[$level_value], 'date' => $current[1], 'text' => $current[2], 'in_file' => isset($current[3]) ? $current[3] : null, 'stack' => preg_replace("/^\n*/", '', $log_data[$i]));
}
}
}
}
$log["data"]['file_path'] = 'logs/' . $file_name;
$log["data"]['file_name'] = $file_name;
$log["data"]['file_size'] = $disk->size('logs/' . $file_name);
$log["data"]['last_modified'] = $disk->lastModified('logs/' . $file_name);
// return array_reverse($log);
return view("logmanager::log_item", ['logs' => array_reverse($log)]);
// return array_reverse($log);
//
// $this->data['log'] = [
// 'file_path' => 'logs/'.$file_name,
// 'file_name' => $file_name,
// 'file_size' => $disk->size('logs/'.$file_name),
// 'last_modified' => $disk->lastModified('logs/'.$file_name),
// 'content' => $disk->get('logs/'.$file_name),
// ];
//
// return view("logmanager::log_item", $this->data);
} else {
abort(404, "The log file doesn't exist.");
}
}
示例9: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Image $image)
{
$this->validate($request, ['name' => 'required', 'tags' => 'required']);
if ($request->hasFile('image')) {
$this->validate($request, ['image' => 'required|image|max:60000']);
$extendedName = $this->storeImage($request);
if (!$extendedName) {
return redirect()->route('admin.images.edit', $image->id)->withDanger("Crap. File was not saved.");
}
$image->path = $extendedName;
$image->size = File::size($extendedName);
}
$image->name = $request->input('name');
$image->tags = $request->input('tags');
$image->save();
return redirect()->route('admin.images.show', $image->id)->withSuccess("Image {$image->name} has been updated.");
}
示例10: getPROGRESS
public function getPROGRESS($filename)
{
// take download progress from temporary file
$progressFILE = "{$this->storagePATH()}{$filename}";
if (File::exists($progressFILE)) {
try {
$progressINFO = json_decode(File::get($progressFILE));
if ($progressINFO->multiple) {
$totalSIZE = $progressINFO->videosSIZE + $this->getMP3SIZE($progressINFO->videosLENGTH);
$currentSIZE = 0;
if (is_dir($progressINFO->videosDIR)) {
$currentSIZE += $this->getDIRSIZE($progressINFO->videosDIR);
}
return $this->calculatePROGRESS($totalSIZE, $currentSIZE);
} else {
$totalSIZE = $progressINFO->videoSIZE + $this->getMP3SIZE($progressINFO->videoLENGTH);
$currentSIZE = 0;
if (File::exists($progressINFO->videoFILE)) {
$currentSIZE += File::size($progressINFO->videoFILE);
}
if (File::exists($progressINFO->mp3FILE)) {
$currentSIZE += File::size($progressINFO->mp3FILE);
}
return $this->calculatePROGRESS($totalSIZE, $currentSIZE);
}
} catch (\Exception $e) {
/* failed decode progress file */
}
}
return null;
}
示例11: url
public function url($filename, $dir = null)
{
$this->results['filename'] = $filename;
$this->results['path'] = rtrim($this->uploadpath, '/') . ($dir ? '/' . trim($dir, '/') : '');
$this->results['dir'] = str_replace(public_path() . '/', '', $this->results['path']);
$this->results['filename'] = $filename;
$this->results['filepath'] = rtrim($this->results['path']) . '/' . $this->results['filename'];
if (File::exists($this->results['filepath'])) {
$this->results['filedir'] = str_replace(public_path() . '/', '', $this->results['filepath']);
$this->results['basename'] = File::name($this->results['filepath']);
$this->results['filesize'] = File::size($this->results['filepath']);
$this->results['extension'] = File::extension($this->results['filepath']);
$this->results['mime'] = File::mimeType($this->results['filepath']);
if ($this->isImage($this->results['mime'])) {
list($width, $height) = getimagesize($this->results['filepath']);
$this->results['width'] = $width;
$this->results['height'] = $height;
if (!empty($this->dimensions) && is_array($this->dimensions)) {
foreach ($this->dimensions as $name => $dimension) {
$suffix = trim($name);
$path = $this->results['path'] . ($this->suffix == false ? '/' . trim($suffix, '/') : '');
$name = $this->results['basename'] . ($this->suffix == true ? '_' . trim($suffix, '/') : '') . '.' . $this->results['extension'];
$pathname = $path . '/' . $name;
if (File::exists($pathname)) {
list($nwidth, $nheight) = getimagesize($pathname);
$filesize = File::size($pathname);
$this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => $pathname, 'filedir' => str_replace(public_path() . '/', '', $pathname), 'width' => $nwidth, 'height' => $nheight, 'filesize' => $filesize];
} else {
$this->results['dimensions'][$suffix] = ['path' => $path, 'dir' => str_replace(public_path() . '/', '', $path), 'filename' => $name, 'filepath' => '#', 'filedir' => '#'];
}
}
}
}
return new Collection($this->results);
}
return null;
}
示例12: insert
public function insert($file_path, $attributes = [])
{
if (!File::exists($file_path)) {
return -1;
}
DB::beginTransaction();
try {
$extension = File::extension($file_path);
$filenameWithoutExtension = $this->filenameWithoutExtension();
$filename = $this->filename($filenameWithoutExtension, $extension);
$size = File::size($file_path);
$save_dir = $this->filePath($this->_dir);
if (!File::exists($save_dir)) {
File::makeDirectory($save_dir);
}
$save_path = $save_dir . '/' . $filename;
File::copy($file_path, $save_path);
DB::commit();
} catch (Exception $e) {
DB::rollback();
return -1;
}
return $this->saveData($filename, $extension, $size, $attributes);
}
示例13: bigUploads
/**
* Big Upload
* ini adalah upload menggunakan metode chuck
* dengan ajax file
*/
public function bigUploads()
{
$bigUpload = new BigUpload();
$folder = $this->uploadfile->getUploadFolder();
$bigUpload->setTempDirectory(public_path('/videos/tmp'));
$bigUpload->setMainDirectory($folder);
$bigUpload->setTempName(Input::get('key', null));
switch (Input::get('action')) {
case 'upload':
return $bigUpload->uploadFile();
break;
case 'abort':
return $bigUpload->abortUpload();
break;
case 'finish':
$rand = Str::random(10);
$randomname = $rand . '.' . Input::get('ext');
$finish = $bigUpload->finishUpload($randomname);
if (0 === $finish['errorStatus']) {
// Create a new order if not exist
if (null === $this->model) {
$this->model = $this->repository->getModel()->newInstance();
/*
//shell_exec("ffmpegthumbnailer -i " . $folder. $randomname ." -o ". static::$app['path.base']."/public/covers/" . $rand . ".png -s 400");
shell_exec("ffmpeg -itsoffset -5 -i ". $folder. $randomname ." -vcodec mjpeg -vframes 5 -an -f rawvideo ".static::$app['path.base']."/public/covers/" . $rand . ".jpg");
//Sonus::convert()->input( $folder. $randomname )->output(static::$app['path.base'].'/public/streams/' . $randomname )->go();
$resolusi = $this->__get_video_dimensions($folder.$randomname);
if($resolusi['height'] >= 720){
shell_exec("ffmpeg -i {$folder}{$randomname} -s 960x720 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_720.mp4");
}
shell_exec("ffmpeg -i {$folder}{$randomname} -s 480×360 -vcodec h264 -acodec aac -strict -2 {$folder}{$rand}_360.mp4");
*/
// File extension
$this->model->code = $rand;
$this->model->extension = File::extension($folder . $randomname);
$this->model->mimetype = File::type($folder . $randomname);
$this->model->owner_id = $this->ownerId;
$this->model->size = File::size($folder . $randomname);
$this->model->path = $this->uploadfile->cleanPath(static::$app['config']->get('video.upload_folder_public_path')) . $this->uploadfile->dateFolderPath;
$this->model->filename = $randomname;
$this->model->playback = $randomname;
$this->model->cover = $rand . '.png';
$this->model->save();
if (null !== $this->model) {
$info = $this->infoRepository->getModel()->where('video_id', $this->model->getId())->first();
// Create a new item
$info = $info ? $info : $this->infoRepository->getModel()->newInstance();
$info->fill(array_merge(array('name' => Input::get('name')), array('video_id' => $this->model->getId())));
if (!$info->save()) {
throw new Exception("Could not create a video info");
}
}
}
return array('errorStatus' => 0, 'id' => $this->model->getId(), 'code' => $this->model->code);
}
return $finish;
break;
case 'post-unsupported':
//return $bigUpload->postUnsupported();
return $this->upload(Input::file('bigUploadFile'));
break;
}
}
示例14: createFileFromChunks
/**
*
* Check if all the parts exist, and
* gather all the parts of the file together
* @param string $dir - the temporary directory holding all the parts of the file
* @param string $fileName - the original file name
* @param string $chunkSize - each chunk size (in bytes)
* @param string $totalSize - original file size (in bytes)
*/
function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize)
{
// count all the parts of this file
$total_files = 0;
foreach (scandir($temp_dir) as $file) {
if (stripos($file, $fileName) !== false) {
$total_files++;
}
}
// check that all the parts are present
// the size of the last part is between chunkSize and 2*$chunkSize
if ($total_files * $chunkSize >= $totalSize - $chunkSize + 1) {
// create the final destination file
if (($fp = fopen($this->mainDirectory . $fileName, 'w')) !== false) {
for ($i = 1; $i <= $total_files; $i++) {
fwrite($fp, file_get_contents($temp_dir . '/' . $fileName . '.part' . $i));
$this->_log($fileName . ' writing chunk ' . $i);
}
fclose($fp);
//set return fileinfo
$this->fileinfo = array('filename' => $fileName, 'extension' => File::extension($this->mainDirectory . $fileName), 'size' => File::size($this->mainDirectory . $fileName));
} else {
$this->_log('cannot create the destination file');
return false;
}
// rename the temporary directory (to avoid access from other
// concurrent chunks uploads) and than delete it
if (rename($temp_dir, $temp_dir . '_UNUSED')) {
$this->rrmdir($temp_dir . '_UNUSED');
} else {
$this->rrmdir($temp_dir);
}
}
}
示例15: showVideo
/**
* Created By Dara on 21/2/2016
* get the video of the session
*/
public function showVideo($videoName)
{
$path = storage_path('app') . '/' . $videoName;
$file = File::get($path);
$type = File::mimeType($path);
$headers = ['Content-Type' => 'video/mp4', 'Content-Length' => File::size($path)];
return Response::stream(function () use($path) {
try {
$stream = fopen($path, 'r');
fpassthru($stream);
} catch (Exception $e) {
Log::error($e);
}
}, 200, $headers);
}