/**
  * Check if an existing file gets found.
  */
 function testExist()
 {
     $filePath = $this->createUserFile('1234');
     if (!$filePath) {
         return;
     }
     $File = new File('user', 1, basename($filePath));
     $this->assertTrue($File->exists(), 'File exists');
     $this->assertTrue($File->get_size() == 4, 'File size is correct');
 }
Example #2
0
 public function test_check_file_size()
 {
     if ($this->is_save_db) {
         \Util_Develop::output_test_info(__FILE__, __LINE__);
         $this->markTestSkipped('File is saved in db.');
     }
     foreach ($this->files as $file) {
         $test = File::get_size(self::check_and_get_file_path($file->path, $file->name));
         $this->assertEquals($file->filesize, $test);
     }
 }
Example #3
0
 public function test_check_file_size()
 {
     foreach ($this->files as $file) {
         $file_path = self::check_and_get_file_path($file->path, $file->name);
         if (!file_exists($file_path)) {
             continue;
         }
         $test = File::get_size($file_path);
         $this->assertEquals($file->filesize, $test);
     }
 }
 public function index()
 {
     //安全验证
     $this->checksafeauth();
     import('ORG.String');
     $nowdir = isset($_GET['dir']) ? urldecode($_GET['dir']) : '';
     $lastdir = empty($nowdir) ? '' : substr($nowdir, 0, strlen($nowdir) - strlen(strrchr($nowdir, '/')));
     $this->assign("lastdir", $lastdir);
     $base = './';
     $root = empty($nowdir) ? $base : $base . $nowdir;
     //$dir =  File::get_dirs($root);
     $d = scandir($root);
     $list = array();
     foreach ($d as $v) {
         $filename = rtrim($root, '/') . '/' . $v;
         if ($v != '.' && $v != '..') {
             if (is_dir($filename)) {
                 $a['filename'] = String::setCharset($v);
                 $a['type'] = 'dir';
                 $a['filesize'] = File::get_size($root . '/' . $v);
                 $b = stat($root . '/' . $v);
                 $a['atime'] = $b['atime'];
                 $a['mtime'] = $b['mtime'];
                 $a['ctime'] = $b['ctime'];
                 $a['is_readable'] = is_readable($root . '/' . $v);
                 $a['is_writeable'] = is_writeable($root . '/' . $v);
                 $a['nowdir'] = urlencode($nowdir . '/' . $v);
                 //$a['empty_dir'] = File::empty_dir($root.'/'.$v);
             } else {
                 $a['filename'] = String::setCharset($v);
                 $a['type'] = 'file';
                 $a['ext'] = substr(strrchr($v, '.'), 1);
                 $b = stat($root . '/' . $v);
                 $a['atime'] = $b['atime'];
                 $a['mtime'] = $b['mtime'];
                 $a['filesize'] = $b['size'];
                 $a['ctime'] = $b['ctime'];
                 $a['is_readable'] = is_readable($root . '/' . $v);
                 $a['is_writeable'] = is_writeable($root . '/' . $v);
                 $a['nowdir'] = urlencode($nowdir . '/' . $v);
             }
             $list[] = $a;
         }
     }
     // echo $list;
     // die();
     $this->assign("list", $list);
     $this->display();
 }
Example #5
0
 public function save($uploaded_file_path = null)
 {
     try {
         if (!$uploaded_file_path) {
             $uploaded_file_path = $this->upload_file();
         }
         $this->set_file_properties($uploaded_file_path);
         if (!Site_Upload::check_and_make_uploaded_dir($this->options['upload_dir'], null, $this->options['path_chmod'])) {
             throw new FuelException('ディレクトリの作成に失敗しました。');
         }
         $tmp_file_path = APPPATH . 'tmp/' . $this->file->name;
         if (!Util_file::move($uploaded_file_path, $tmp_file_path)) {
             throw new FuelException('Save raw file error.');
         }
         // exif データの取得
         $exif = array();
         if ($this->options['is_save_exif_to_db'] && $this->file->type == 'image/jpeg') {
             $exif = \Util_Exif::get_exif($tmp_file_path, $this->options['exif_accept_tags'], $this->options['exif_ignore_tags']);
         }
         $is_resaved = false;
         // 回転状態の補正
         if ($this->options['auto_orient'] && !empty($exif['Orientation'])) {
             Util_file::correct_orientation($tmp_file_path, $exif['Orientation']);
             $is_resaved = true;
         }
         // 大きすぎる場合はリサイズ & 保存ファイルから exif 情報削除
         $file_size_before = $this->file->size;
         if ($max_size = Site_Upload::get_accepted_max_size($this->options['member_id'])) {
             $this->file->size = Site_Upload::check_max_size_and_resize($tmp_file_path, $max_size);
             $is_resaved = $this->file->size != $file_size_before;
         }
         if ($this->options['is_clear_exif_on_file'] && !$is_resaved) {
             Site_Upload::clear_exif($tmp_file_path);
             $this->file->size = File::get_size($tmp_file_path);
         }
         $this->save_model_file($exif);
         $this->save_file_bin($tmp_file_path);
     } catch (\FuelException $e) {
         if (isset($this->file->file_path) && file_exists($this->file->file_path)) {
             Util_file::remove($this->file->file_path);
             $this->file->size = filesize($this->file->file_path);
         }
         $this->file->error = $e->getMessage();
     }
     return $this->file;
 }
Example #6
0
 public function get_size($path)
 {
     return \File::get_size($path, $this);
 }
Example #7
0
 public static function clear_exif($path, $driver = null)
 {
     if (!$driver) {
         $driver = Config::get('image.driver');
     }
     if (FBD_IMAGE_DRIVER == 'imagemagick') {
         $command = FBD_IMAGE_IMGMAGICK_PATH . 'convert';
         $params = sprintf('"%s" -strip "%s"', $path, $path);
         Util_Toolkit::exec_command($command, $params, false, true);
     } elseif (FBD_IMAGE_DRIVER == 'imagick') {
         $im = new \Imagick($path);
         $im->stripImage();
         $im->writeImage($path);
         $im->destroy();
     } else {
         Util_file::resave($path);
     }
     return File::get_size($path);
 }
Example #8
0
 protected function handle_file_upload($uploaded_file, $original_name, $size, $type, $error, $index = null, $content_range = null)
 {
     $file = new \stdClass();
     $file->is_tmp = $this->options['is_tmp'];
     $file->original_name = $original_name;
     $file->size = $this->fix_integer_overflow(intval($size));
     $file->type = $type;
     if (!($extention = Util_file::check_file_type($uploaded_file, \Site_Upload::get_accept_format($this->options['upload_type']), $type, $this->options['upload_type']))) {
         $file->error = $this->get_error_message('accept_file_types');
         return $file;
     }
     if (!($filename_with_prefix = Site_Upload::make_unique_filename($extention, $this->options['filename_prefix'], $original_name))) {
         $file->error = 'ファイル名の作成に失敗しました。';
         return $file;
     }
     $file->name = $this->remove_filename_prefix($filename_with_prefix);
     $file->name_prefix = $this->options['filename_prefix'];
     if (!\Site_Upload::check_and_make_uploaded_dir($this->options['upload_dir'], null, $this->options['mkdir_mode'])) {
         $file->error = 'ディレクトリの作成に失敗しました。';
         return $file;
     }
     if (!$this->validate($uploaded_file, $file, $error, $index)) {
         return $file;
     }
     if ($this->options['upload_type'] == 'img') {
         $file->thumbnail_uri = $this->options['image_versions']['thumbnail']['upload_url'] . $file->name;
     }
     $this->handle_form_data($file, $index);
     $upload_dir = $this->get_upload_path();
     $file_path = $this->get_upload_path($file->name);
     $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path);
     if ($uploaded_file && is_uploaded_file($uploaded_file)) {
         // multipart/formdata uploads (POST method uploads)
         if ($append_file) {
             file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
         } else {
             $res = move_uploaded_file($uploaded_file, $file_path);
         }
     } else {
         // Non-multipart uploads (PUT method support)
         file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
     }
     $file_size = $this->get_file_size($file_path, $append_file);
     if ($file_size === $file->size) {
         $file->url = $this->get_download_url($file->name);
         if ($this->is_valid_image_file($file_path)) {
             $this->handle_image_file($file_path, $file);
         }
     } else {
         $file->size = $file_size;
         if (!$content_range && $this->options['discard_aborted_uploads']) {
             $this->delete_file($filename_with_prefix, $this->options['storage_type']);
             $file->error = 'abort';
         }
     }
     $this->set_additional_file_properties($file);
     // exif データの取得
     $exif = array();
     if ($this->options['is_save_exif_to_db'] && $extention == 'jpg') {
         $exif = \Util_Exif::get_exif($file_path, $this->options['exif_accept_tags'], $this->options['exif_ignore_tags']);
     }
     if ($this->options['upload_type'] == 'img') {
         // 大きすぎる場合はリサイズ & 保存ファイルから exif 情報削除
         $file_size_before = $file->size;
         if ($this->options['member_id'] && $this->options['user_type'] === 0 && ($max_size = Site_Upload::get_accepted_max_size($this->options['member_id']))) {
             $file->size = Site_Upload::check_max_size_and_resize($file_path, $max_size);
         }
         // Exif情報の削除
         $is_resaved = $file->size != $file_size_before;
         if ($this->options['is_clear_exif_on_file'] && !$is_resaved) {
             Site_Upload::clear_exif($file_path);
             $file->size = File::get_size($file_path);
         }
         if (!empty($this->options['accept_sizes'])) {
             $file->accept_sizes = $this->options['accept_sizes'];
         }
     }
     try {
         if ($this->options['storage_type'] != 'normal') {
             $this->save_file2storage($file_path, $filename_with_prefix);
             $this->delete_file($filename_with_prefix, $this->options['storage_type'], false, false);
         }
         $file->id = $this->save_file($file, $exif);
     } catch (\Exception $e) {
         if ($this->options['is_output_log_save_error']) {
             \Util_Toolkit::log_error(sprintf('file save error: %s', $e->getMessage()));
         }
         $this->delete_file($filename_with_prefix, $this->options['storage_type']);
         $file->error = 'ファイルの保存に失敗しました。';
     }
     return $file;
 }