本文整理汇总了PHP中File::size方法的典型用法代码示例。如果您正苦于以下问题:PHP File::size方法的具体用法?PHP File::size怎么用?PHP File::size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::size方法的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");
}
示例2: sendFile
/**
* Start a big file download on Laravel Framework 4.0 / 4.1
* Source (originally for Laravel 3.*) : http://stackoverflow.com/questions/15942497/why-dont-large-files-download-easily-in-laravel
* @param string $path Path to the big file
* @param string $name Name of the file (used in Content-disposition header)
* @param array $headers Some extra headers
*/
public function sendFile($path, $name = null, array $headers = array())
{
if (is_null($name)) {
$name = basename($path);
}
$file = new \Symfony\Component\HttpFoundation\File\File($path);
$mime = $file->getMimeType();
// Prepare the headers
$headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => $mime, 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => \File::size($path), 'Content-Disposition' => 'attachment; filename=' . $name), $headers);
$response = new \Symfony\Component\HttpFoundation\Response('', 200, $headers);
// If there's a session we should save it now
if (\Config::get('session.driver') !== '') {
\Session::save();
}
session_write_close();
if (ob_get_length()) {
ob_end_clean();
}
$response->sendHeaders();
// Read the file
if ($file = fopen($path, 'rb')) {
while (!feof($file) and connection_status() == 0) {
print fread($file, 1024 * 8);
flush();
}
fclose($file);
}
// Finish off, like Laravel would
\Event::fire('laravel.done', array($response));
$response->send();
}
示例3: main
function main()
{
if (empty($this->args)) {
return $this->err('Usage: ./cake fixturize <table>');
}
if ($this->args[0] == '?') {
return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]');
}
$options = array('force' => false, 'reindex' => false);
foreach ($this->params as $key => $val) {
foreach ($options as $name => $option) {
if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
$options[$name] = true;
}
}
}
foreach ($this->args as $table) {
$name = Inflector::classify($table);
$Model = new AppModel(array('name' => $name, 'table' => $table));
$file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name));
$File = new File($file);
if ($File->exists() && !$options['force']) {
$this->err(sprintf('File %s already exists, use --force option.', $file));
continue;
}
$records = $Model->find('all');
$out = array();
$out[] = '<?php';
$out[] = '';
$out[] = sprintf('class %sFixture extends CakeTestFixture {', $name);
$out[] = sprintf(' var $name = \'%s\';', $name);
$out[] = ' var $records = array(';
$File->write(join("\n", $out));
foreach ($records as $record) {
$out = array();
$out[] = ' array(';
if ($options['reindex']) {
foreach (array('old_id', 'vendor_id') as $field) {
if ($Model->hasField($field)) {
$record[$name][$field] = $record[$name]['id'];
break;
}
}
$record[$name]['id'] = String::uuid();
}
foreach ($record[$name] as $field => $val) {
$out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'"));
}
$out[] = ' ),';
$File->write(join("\n", $out));
}
$out = array();
$out[] = ' );';
$out[] = '}';
$out[] = '';
$out[] = '?>';
$File->write(join("\n", $out));
$this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file));
}
}
示例4: beforeSave
/**
* beforeSave callback
*
* @param array $options
* @return boolean true on success
*/
public function beforeSave($options = array())
{
if (!empty($this->data[$this->alias]['file']['tmp_name'])) {
$File = new File($this->data[$this->alias]['file']['tmp_name']);
$this->data[$this->alias]['filesize'] = $File->size();
$this->data[$this->alias]['mime_type'] = $File->mime();
}
if (!empty($this->data[$this->alias]['file']['name'])) {
$this->data[$this->alias]['extension'] = $this->fileExtension($this->data[$this->alias]['file']['name']);
$this->data[$this->alias]['filename'] = $this->data[$this->alias]['file']['name'];
}
if (empty($this->data[$this->alias]['adapter'])) {
$this->data[$this->alias]['adapter'] = 'S3Storage';
}
// Start Auto Creator & Modifier Id Saving
$exists = $this->exists();
$user = class_exists('CakeSession') ? CakeSession::read('Auth.User') : null;
if (!$exists && $this->hasField('creator_id') && empty($this->data[$this->alias]['creator_id'])) {
$this->data[$this->alias]['creator_id'] = $user['id'];
}
if ($this->hasField('modifier_id') && empty($this->data[$this->alias]['modifier_id'])) {
$this->data[$this->alias]['modifier_id'] = $user['id'];
}
// End Auto Creator & Modifier Id Saving
$Event = new CakeEvent('FileStorage.beforeSave', $this, array('record' => $this->data, 'storage' => $this->getStorageAdapter($this->data[$this->alias]['adapter'])));
$this->getEventManager()->dispatch($Event);
if ($Event->isStopped()) {
return false;
}
return true;
}
示例5: postUpload
public function postUpload()
{
$agente = Agente::find(1);
if (Input::hasFile('file')) {
$file = Input::file('file');
$name = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$size = File::size($file);
//dd($extension);
$data = array('nombre' => $name, 'extension' => $extension, 'size' => $size);
$rules = array('extension' => 'required|mimes:jpeg');
$messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'unique' => 'La factura ingresada ya está agregada en la base de datos.', 'confirmed' => 'Los passwords no coinciden.', 'mimes' => 'El campo :attribute debe ser un archivo de tipo :values.');
$validation = Validator::make($rules, $messages);
if ($validation->fails()) {
return Redirect::route('logo-post')->withInput()->withErrors($validation);
} else {
if ($extension != 'jpg') {
return Redirect::route('logo-post')->with('global', 'Es necesario que la imagen sea de extension .jpg.');
} else {
$path = public_path() . '/assets/img/';
$newName = 'logo';
$subir = $file->move($path, $newName . '.' . $extension);
return Redirect::route('agente.index')->with('create', 'El logo ha sido actualizado correctamente!');
}
}
} else {
return Redirect::route('logo-post')->with('global', 'Es necesario que selecciones una imagen.');
}
}
示例6: replace
function replace($path)
{
$F = new File($path);
$md5 = $F->md5();
$this->path = appPATH . 'qg/file/' . $md5;
$F->copy($this->path);
$this->setVs(array('name' => $F->basename(), 'mime' => $F->mime(), 'text' => $F->getText(), 'md5' => $F->md5(), 'size' => $F->size()));
}
示例7: setFiles
protected final function setFiles($key, $req)
{
$file = new File($req["name"]);
$file->tmp(isset($req["tmp_name"]) ? $req["tmp_name"] : "");
$file->size(isset($req["size"]) ? $req["size"] : "");
$file->error($req["error"]);
$this->files[$key] = $file;
}
示例8: admin_index
public function admin_index()
{
$logDir = LOGS;
$Folder = new Folder($logDir, false);
$logfiles = $Folder->find('.*.log(\\.[0-9])?', true);
$files = array();
foreach ($logfiles as $logfile) {
$F = new File($logDir . $logfile);
$file = array('name' => $logfile, 'dir' => $logDir, 'size' => $F->size(), 'last_modified' => $F->lastChange(), 'last_access' => $F->lastAccess());
array_push($files, $file);
}
$this->set(compact('files'));
}
示例9: save
/**
* Save the file to the fileable type and id
*/
public function save()
{
$file = $this->makeFileRecord();
// move the file and add the size to the file model
$this->file->move($file->getSystemPath(), $file->filename);
if (\File::exists($file->getSystemPath() . $file->filename)) {
$file->filesize = \File::size($file->getSystemPath() . $file->filename);
}
if ($this->thumbnail->isPhoto($file->getSystemPath() . $file->filename)) {
$this->thumbnail->make($file);
}
$file->save();
}
示例10: saveFile
/**
* Finished Benchmarks and log texts will be added to the logfile.
*
* Each benchmark is one row in the file. After calling this function successfully, the finished
* benchmarks array and the log data array are empty. It is not recommended to use this function
* directly. If an error occurs while writing the file a NonFatalException will be thrown.
*
* @throws NonFatalException
*/
public function saveFile() {
$benchmarks = array();
//add new line if file is not empty
$text = $this->file->size() != 0 ? "\r\n" : '';
$benchmarks = $this->getBenchmarkStringArray();
$text .= implode("\r\n", array_merge($this->logs, $benchmarks));
if ($this->file->write($text, true) === false) {
throw NonFatalException('Could not write to log file.');
}
else {
$this->clear();
}
}
示例11: saveFile
/**
* Finished Benchmarks and log texts will be added to the logfile.
*
* Each benchmark is one row in the file.
* After calling this function successfully, the finished benchmarks array and the log data array are empty.
* It is not recommended to use this function directly.
* If an error occurs while writing the file a warning will be thrown.
*/
public function saveFile()
{
$benchmarks = array();
//add new line if file is not empty
$text = iif($this->file->size() != 0 && $this->file->size() != false, "\r\n");
$benchmarks = $this->getBenchmarkStringArray();
$text .= implode("\r\n", array_merge($this->logs, $benchmarks));
if ($this->file->write($text, true) === false) {
Core::throwError('Could not write log file in method Debug::saveFile().');
} else {
$this->clear();
}
}
示例12: readFolder
function readFolder($folderName = null)
{
$folder = new Folder($folderName);
$images = $folder->read(true, array('.', '..', 'Thumbs.db'), false);
//pr($folder->tree($folderName));
$images = $images[1];
// We are only interested in files
// Get more infos about the images
$retVal = array();
foreach ($images as $the_image) {
$the_image = new File($the_image);
$retVal[] = array_merge($the_image->info(), array('size' => $the_image->size(), 'last_changed' => $the_image->lastChange()));
}
return $retVal;
}
示例13: load
/**
* Reads a cache file and unserializes the data.
*
* @param string Cache name
* @return Cached data or null on failure
*/
public function load($name) {
$file = new File($this->path.$name.'.ser');
if ($file->exists() == true && $file->size() > 0) {
$data = $file->read();
if ($data !== false) {
$data = unserialize($data);
if (isset($data['expires']) && ($data['expires'] == 0 || $data['expires'] > time())) {
return $data['data'];
}
else {
$this->delete();
}
}
}
return null;
}
示例14: indx
public function indx()
{
//Getting all post data
if (Request::ajax()) {
$data = Input::all();
$fileTblObj = new fileHandler();
$key = "uploaded_file";
if (Input::file($key)->isValid()) {
$destinationPath = 'app/uploads/111/222/3';
// upload path
$extension = Input::file($key)->getClientOriginalExtension();
// getting image extension
$name = Input::file($key)->getClientOriginalName();
$curFilesize = Input::file($key)->getClientSize();
$mime = Input::file($key)->getMimeType();
// dd($mime);
//$fileName = $name; // renameing image
//$exstFileSize = Input::file($destinationPath, $fileName);
if (!File::exists($destinationPath . "/boq-" . $name)) {
//creating details for saving inthe file_handler Table
$fileTblObj->user_id = $userid;
$fileTblObj->eventName = $event;
$fileTblObj->fileName = "boq-" . $name;
$fileTblObj->formPage = 3;
$fileTblObj->filePath = $destinationPath . "/";
$fileTblObj->mime = $mime;
$ans->answer_text = 'Yes';
Input::file($key)->move($destinationPath, "boq-" . $name);
// uploading file to given path
//Input::file($key)->move($boqPath, $boqname); // uploading file to given path
//Save filedetails
$fileTblObj->save();
Session::flash('success', 'Upload successfully');
} else {
if (File::size($destinationPath . "/" . $name) != $curFilesize) {
$fileDtls = $fileTblObj->where('uid', $userid)->where('fileName', $name)->where('formPage', 3)->first();
Input::file($key)->move($destinationPath, $name);
$ans->answer_text = 'Yes';
$ans->save();
$fileTblObj->where('id', $fileDtls->id)->update(array('updated_at' => date("Y-m-d h:m:s", time())));
}
}
//return Redirect::to('upload');
}
die;
}
}
示例15: finish
public function finish()
{
if ($this->isCache) {
return null;
}
if ($this->handle) {
ob_end_flush();
fclose($this->handle);
}
if (App::hasError()) {
return null;
}
if (File::size($this->cacheTmp) > 0) {
copy($this->cacheTmp, $this->cacheName);
file_put_contents($this->cacheName . '.1', $this->lastModified);
}
}