コード例 #1
0
ファイル: Simple.php プロジェクト: andrewkrug/repucaution
 /**
  * Get unique but consistent name
  * @param  string  $name
  * @param  string  $type
  * @param  integer $index
  * @param  array   $content_range
  * @return string
  */
 protected function getUniqueFilename($name, $type, $index, $content_range)
 {
     while ($this->filesystem->isDir($this->pathresolver->getUploadPath($name))) {
         $name = $this->pathresolver->upcountName($name);
     }
     $uploaded_bytes = Util::fixIntegerOverflow(intval($content_range[1]));
     while ($this->filesystem->isFile($this->pathresolver->getUploadPath($name))) {
         if ($uploaded_bytes == $this->filesystem->getFilesize($this->pathresolver->getUploadPath($name))) {
             break;
         }
         $name = $this->pathresolver->upcountName($name);
     }
     return $name;
 }
コード例 #2
0
ファイル: FileUpload.php プロジェクト: andrewkrug/repucaution
 /**
  * Validate upload using some default rules, and custom
  * validators added via addValidator. Default rules:
  *
  * - No PHP errors from $_FILES
  * - File size permitted by PHP config
  *
  * @param  string  $tmp_name
  * @param  File    $file
  * @param  integer $error
  * @param  integer $index
  * @return boolean
  */
 protected function validate($tmp_name, File $file, $error, $index)
 {
     if ($error !== 0) {
         // PHP error
         $file->error = $this->messages[$error];
         $file->error_code = $error;
         return false;
     }
     $content_length = $this->getContentLength();
     $post_max_size = $this->getConfigBytes(ini_get('post_max_size'));
     $upload_max_size = $this->getConfigBytes(ini_get('upload_max_filesize'));
     if ($post_max_size && $content_length > $post_max_size || $upload_max_size && $content_length > $upload_max_size) {
         // Uploaded file exceeds maximum filesize PHP accepts in the configs
         $file->error = $this->messages[self::UPLOAD_ERR_PHP_SIZE];
         $file->error_code = self::UPLOAD_ERR_PHP_SIZE;
         return false;
     }
     if ($tmp_name && $this->filesystem->isUploadedFile($tmp_name)) {
         $current_size = $this->getFilesize($tmp_name);
     } else {
         $current_size = $content_length;
     }
     // Now that we passed basic, implementation-agnostic tests,
     // let's do custom validators
     foreach ($this->validators as $validator) {
         if (!$validator->validate($tmp_name, $file, $current_size)) {
             return false;
         }
     }
     return true;
 }