소스 검색

fixed file upload

Fabien Potencier 15 년 전
부모
커밋
fc9325a737

+ 1 - 1
src/Symfony/Component/File/File.php

@@ -466,7 +466,7 @@ class File
      */
     public function __toString()
     {
-        return $this->getPath();
+        return null === $this->getPath() ? '' : $this->getPath();
     }
 
     /**

+ 3 - 1
src/Symfony/Component/File/UploadedFile.php

@@ -43,7 +43,9 @@ class UploadedFile extends File
             throw new FileException(sprintf('Unable to create UploadedFile because "file_uploads" is disabled in your php.ini file (%s)', get_cfg_var('cfg_file_path')));
         }
 
-        parent::__construct($path);
+        if (is_file($path)) {
+            $this->path = realpath($path);
+        }
 
         if (is_null($error)) {
             $error = UPLOAD_ERR_OK;

+ 6 - 2
src/Symfony/Component/Validator/Constraints/FileValidator.php

@@ -20,6 +20,10 @@ class FileValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
+        if ($value instanceof FileObject && null === $value->getPath()) {
+            return true;
+        }
+
         $path = $value instanceof FileObject ? $value->getPath() : (string)$value;
 
         if (!file_exists($path)) {
@@ -39,11 +43,11 @@ class FileValidator extends ConstraintValidator
                 $size = filesize($path);
                 $limit = $constraint->maxSize;
                 $suffix = ' bytes';
-            } else if (preg_match('/^(\d)k$/', $constraint->maxSize, $matches)) {
+            } else if (preg_match('/^(\d+)k$/', $constraint->maxSize, $matches)) {
                 $size = round(filesize($path) / 1000, 2);
                 $limit = $matches[1];
                 $suffix = ' kB';
-            } else if (preg_match('/^(\d)M$/', $constraint->maxSize, $matches)) {
+            } else if (preg_match('/^(\d+)M$/', $constraint->maxSize, $matches)) {
                 $size = round(filesize($path) / 1000000, 2);
                 $limit = $matches[1];
                 $suffix = ' MB';