fixed file upload
This commit is contained in:
parent
40c0fe854f
commit
fc9325a737
@ -466,7 +466,7 @@ class File
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getPath();
|
||||
return null === $this->getPath() ? '' : $this->getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user