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


PHP File::size方法代码示例

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


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

示例1: edit

 /**
  *  Image manipulation view - Includes a small toolbox for basic
  *  image editing before saving or discarding changes
  */
 public function edit($id, $action = null, array $params = null)
 {
     $image = $this->Images->get($id, ['contain' => 'Uploads']);
     if ($this->request->is(['post', 'put'])) {
         $imgFile = new File($image->upload->full_path);
         // Backup original
         $backupFile = new File(TMP . DS . time() . 'bak');
         $imgFile->copy($backupFile->path);
         if (!$image->hasTmp()) {
             return $this->Flash->error('Sorry, we lost your edit...');
         }
         // Open tmp file
         $tmpFile = new File($image->tmp_path_full);
         // Copy tmp file to permanent location
         if (!$tmpFile->copy($imgFile->path)) {
             return $this->Flash->error('Could not save image');
         }
         // Change recorded image dimentions and size
         $image->upload->size = $tmpFile->size();
         $image->width = $this->Image->width($tmpFile->path);
         $image->height = $this->Image->height($tmpFile->path);
         // Delete tmp file
         $image->deleteTmp();
         if (!$this->Images->save($image)) {
             // Restore file with matching, original size and dimentions
             $backupFile->copy($imgFile->path);
             $backupFile->delete();
             $this->Flash->error('Could not save image.');
             return $this->redirect();
         } else {
             $this->Flash->success('Image edited successfully.');
             return $this->redirect();
         }
     } else {
         if (!$image->hasTmp()) {
             $image->makeTmp();
         }
     }
     $this->set(['image' => $image, 'route' => $this->RedirectUrl->load()]);
 }
开发者ID:propellerstudios,项目名称:UploadManager,代码行数:44,代码来源:ImagesController.php

示例2: _fileRange

 /**
  * Apply a file range to a file and set the end offset.
  *
  * If an invalid range is requested a 416 Status code will be used
  * in the response.
  *
  * @param File $file The file to set a range on.
  * @param string $httpRange The range to use.
  * @return void
  */
 protected function _fileRange($file, $httpRange)
 {
     list(, $range) = explode('=', $httpRange);
     list($start, $end) = explode('-', $range);
     $fileSize = $file->size();
     $lastByte = $fileSize - 1;
     if ($start === '') {
         $start = $fileSize - $end;
         $end = $lastByte;
     }
     if ($end === '') {
         $end = $lastByte;
     }
     if ($start > $end || $end > $lastByte || $start > $lastByte) {
         $this->statusCode(416);
         $this->header(['Content-Range' => 'bytes 0-' . $lastByte . '/' . $fileSize]);
         return;
     }
     $this->header(['Content-Length' => $end - $start + 1, 'Content-Range' => 'bytes ' . $start . '-' . $end . '/' . $fileSize]);
     $this->statusCode(206);
     $this->_fileRange = [$start, $end];
 }
开发者ID:rabinpal,项目名称:cakephp,代码行数:32,代码来源:Response.php

示例3: fileToUploadArray

 /**
  * Returns an array that matches the structure of a regular upload for a local file
  *
  * @param $file The file you want to get an upload array for.
  * @param string Name of the file to use in the upload array.
  * @return array Array that matches the structure of a regular upload
  */
 public static function fileToUploadArray($file, $filename = null)
 {
     $File = new File($file);
     if (empty($fileName)) {
         $filename = basename($file);
     }
     return ['name' => $filename, 'tmp_name' => $file, 'error' => 0, 'type' => $File->mime(), 'size' => $File->size()];
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:15,代码来源:StorageUtils.php

示例4: _upload

 /**
  * [_upload description]
  * @param  string  $fileName [description]
  * @param  string  $filePath [description]
  * @param  bool $copy     [description]
  * @return array            [description]
  */
 protected function _upload($fileName, $filePath, $copy = false)
 {
     $data = [];
     if (!file_exists($filePath) || !$this->_isImage($filePath)) {
         return $data;
     }
     $basePath = $this->basePath();
     $pathinfo = pathinfo($fileName);
     $fileName = md5_file($filePath) . '.' . $pathinfo['extension'];
     $fullPath = $basePath . DS . $fileName;
     $folder = new Folder($basePath, true, 0777);
     $transferFn = $copy || !is_uploaded_file($filePath) ? 'copy' : 'move_uploaded_file';
     $existing = file_exists($fullPath);
     if ($existing || call_user_func_array($transferFn, [$filePath, $fullPath])) {
         $file = new File($fullPath);
         $data = ['filename' => $fileName, 'size' => $file->size(), 'mime' => $file->mime()];
     }
     return $data;
 }
开发者ID:edukondaluetg,项目名称:image,代码行数:26,代码来源:ImageBehavior.php

示例5: _fileRange

 /**
  * Apply a file range to a file and set the end offset.
  *
  * If an invalid range is requested a 416 Status code will be used
  * in the response.
  *
  * @param \Cake\Filesystem\File $file The file to set a range on.
  * @param string $httpRange The range to use.
  * @return void
  */
 protected function _fileRange($file, $httpRange)
 {
     $fileSize = $file->size();
     $lastByte = $fileSize - 1;
     $start = 0;
     $end = $lastByte;
     preg_match('/^bytes\\s*=\\s*(\\d+)?\\s*-\\s*(\\d+)?$/', $httpRange, $matches);
     if ($matches) {
         $start = $matches[1];
         $end = isset($matches[2]) ? $matches[2] : '';
     }
     if ($start === '') {
         $start = $fileSize - $end;
         $end = $lastByte;
     }
     if ($end === '') {
         $end = $lastByte;
     }
     if ($start > $end || $end > $lastByte || $start > $lastByte) {
         $this->statusCode(416);
         $this->header(['Content-Range' => 'bytes 0-' . $lastByte . '/' . $fileSize]);
         return;
     }
     $this->header(['Content-Length' => $end - $start + 1, 'Content-Range' => 'bytes ' . $start . '-' . $end . '/' . $fileSize]);
     $this->statusCode(206);
     $this->_fileRange = [$start, $end];
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:37,代码来源:Response.php

示例6: getFileInfoFromUpload

 /**
  * Gets information about the file that is being uploaded.
  * - gets the file size
  * - gets the mime type
  * - gets the extension if present
  * - sets the adapter by default to local if not already set
  * - sets the model field to the table name if not already set
  *
  * @param array|\ArrayAccess $upload
  * @param string $field
  * @return void
  */
 public function getFileInfoFromUpload(&$upload, $field = 'file')
 {
     if (!empty($upload[$field]['tmp_name'])) {
         $File = new File($upload[$field]['tmp_name']);
         $upload['filesize'] = $File->size();
         $upload['mime_type'] = $File->mime();
     }
     if (!empty($upload[$field]['name'])) {
         $upload['extension'] = pathinfo($upload[$field]['name'], PATHINFO_EXTENSION);
         $upload['filename'] = $upload[$field]['name'];
     }
 }
开发者ID:tiagocapelli,项目名称:cakephp-file-storage,代码行数:24,代码来源:FileStorageTable.php

示例7: testAppend

 /**
  * testAppend method
  *
  * @return void
  */
 public function testAppend()
 {
     if (!($tmpFile = $this->_getTmpFile())) {
         return false;
     }
     if (file_exists($tmpFile)) {
         unlink($tmpFile);
     }
     $TmpFile = new File($tmpFile);
     $this->assertFalse(file_exists($tmpFile));
     $fragments = ['CakePHP\'s', ' test suite', ' was here ...'];
     $data = null;
     $size = 0;
     foreach ($fragments as $fragment) {
         $r = $TmpFile->append($fragment);
         $this->assertTrue($r);
         $this->assertTrue(file_exists($tmpFile));
         $data = $data . $fragment;
         $this->assertEquals($data, file_get_contents($tmpFile));
         $newSize = $TmpFile->size();
         $this->assertTrue($newSize > $size);
         $size = $newSize;
         $TmpFile->close();
     }
     $TmpFile->append('');
     $this->assertEquals($data, file_get_contents($tmpFile));
     $TmpFile->close();
 }
开发者ID:Slayug,项目名称:castor,代码行数:33,代码来源:FileTest.php

示例8: _upload

 /**
  * Upload function.
  *
  * @param string $fileName Original name of the tmp file.
  * @param string $filePath Full path to the tmp file.
  * @param bool $copy Whether copy or move the tmp file.
  * @return array
  */
 protected function _upload($fileName, $filePath, $copy = false)
 {
     $data = [];
     if (!file_exists($filePath)) {
         return $data;
     }
     $fileName = $this->generateUniqueFilename($fileName, $filePath);
     $basePath = $this->basePath();
     $fullPath = $basePath . DS . $fileName;
     $folder = new Folder($basePath, true, 0775);
     $transferFn = $copy ? 'copy' : 'move_uploaded_file';
     if (file_exists($fullPath) || call_user_func_array($transferFn, [$filePath, $fullPath])) {
         $file = new File($fullPath);
         if (false !== $file->size()) {
             $data = ['filename' => $fileName, 'size' => $file->size(), 'mime' => $file->mime(), 'created' => Time::now()];
         }
     }
     return $data;
 }
开发者ID:karolak,项目名称:cakephp-image,代码行数:27,代码来源:ImageBehavior.php

示例9: hacerBackup

 public function hacerBackup()
 {
     if ($this->request->is('post')) {
         $nombre = date('Y-m-d_His') . '_backup.php';
         $archivo = new File($nombre, true, 0777);
         $tablas = array();
         foreach ($this->request->data as $nombreTabla => $value) {
             if ($value == 1) {
                 $tabla = TableRegistry::get($nombreTabla);
                 $registros = $tabla->find('all');
                 //debug($tabla, true, true);
                 //debug($registros, true, true);
                 $tablas[$nombreTabla] = array();
                 foreach ($registros as $entidad) {
                     $tablas[$nombreTabla][] = $entidad->toArray();
                 }
             }
         }
         //Para exportar los datos al archivo en forma de array
         $bytes = @file_put_contents($archivo->info['basename'], "<?php return " . var_export($tablas, true) . ";");
         debug('Tamaño: ' . $archivo->size(), true, true);
         debug('Tamaño: ' . $bytes, true, true);
         if ($bytes > 9) {
             //Para descargar el archivo creado
             $this->response->file($archivo->path, ['download' => true]);
         } else {
             $this->Flash->error(__('Debe seleccionar al menos una tabla.'));
         }
     }
 }
开发者ID:EPSZ-DAW2,项目名称:daw2-2015-recetas-cocina,代码行数:30,代码来源:UsuariosController.php

示例10: rotate

 /**
  * Rotate image based on degree value
  * 
  * @param Image image - image to manipulate
  * @params array params - manipulation parameters
  *      [degree] - degree to rotate by
  * 
  * @return Image Image entity with new dimensions and size
  */
 public function rotate(Image $image, array $params)
 {
     $path = $image->path();
     $edit = $this->imagine->open($path);
     $edit->rotate($params['degree'])->save($path);
     // Set new size
     $file = new File($path);
     $size = $file->size();
     $image->upload->size = $size;
     $image->width = $edit->getSize()->getWidth();
     $image->height = $edit->getSize()->getHeight();
     return $image;
 }
开发者ID:propellerstudios,项目名称:UploadManager,代码行数:22,代码来源:ImageComponent.php


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