pub struct UploadedFile { /* private fields */ }Expand description
上传文件类 — 对齐 PHP think\file\UploadedFile
PHP 第 18-34 行:
class UploadedFile extends File {
private $test = false;
private $originalName;
private $mimeType;
private $error;
public function __construct(string $path, string $originalName, string $mimeType = null, int $error = null, bool $test = false) {
$this->originalName = $originalName;
$this->mimeType = $mimeType ?: 'application/octet-stream';
$this->test = $test;
$this->error = $error ?: UPLOAD_ERR_OK;
parent::__construct($path, UPLOAD_ERR_OK === $this->error);
}
}Implementations§
Source§impl UploadedFile
impl UploadedFile
Sourcepub fn new<P>(
path: P,
original_name: &str,
mime_type: Option<&str>,
error: Option<i32>,
test: bool,
) -> Result<UploadedFile, UploadError>
pub fn new<P>( path: P, original_name: &str, mime_type: Option<&str>, error: Option<i32>, test: bool, ) -> Result<UploadedFile, UploadError>
创建 UploadedFile 实例 — 对齐 PHP UploadedFile::__construct 第 26-34 行
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
验证上传文件 — 对齐 PHP UploadedFile::isValid() 第 36-41 行
PHP 行为:
public function isValid(): bool {
$isOk = UPLOAD_ERR_OK === $this->error;
return $this->test ? $isOk : $isOk && is_uploaded_file($this->getPathname());
}Rust 端:is_uploaded_file 是 PHP SAPI 函数,无法精确对齐。
简化为检查文件是否存在(非 test 模式)。
Sourcepub fn move_to<P>(
&mut self,
directory: P,
name: Option<&str>,
) -> Result<File, UploadError>
pub fn move_to<P>( &mut self, directory: P, name: Option<&str>, ) -> Result<File, UploadError>
移动上传文件 — 对齐 PHP UploadedFile::move() 第 50-75 行
PHP 行为:
isValid()失败 → 抛FileException($this->getErrorMessage())test模式:调用parent::move()(即rename)- 非 test 模式:
move_uploaded_file($pathname, $target) - 失败抛
FileException chmod($target, 0666 & ~umask())- 返回新
File
Sourcepub fn original_mime(&self) -> &str
pub fn original_mime(&self) -> &str
获取原始 MIME — 对齐 PHP UploadedFile::getOriginalMime() 第 112-115 行
Sourcepub fn original_name(&self) -> &str
pub fn original_name(&self) -> &str
获取原始文件名 — 对齐 PHP UploadedFile::getOriginalName() 第 121-124 行
Sourcepub fn original_extension(&self) -> String
pub fn original_extension(&self) -> String
获取原始扩展名 — 对齐 PHP UploadedFile::getOriginalExtension() 第 130-133 行
PHP 行为:return pathinfo($this->originalName, PATHINFO_EXTENSION);
Sourcepub fn extension(&self) -> String
pub fn extension(&self) -> String
获取文件扩展名 — 对齐 PHP UploadedFile::extension() 第 139-142 行
PHP 行为:覆写父类,返回原始扩展名。
public function extension(): string {
return $this->getOriginalExtension();
}Sourcepub fn error_message(&self) -> &'static str
pub fn error_message(&self) -> &'static str
获取错误信息 — 对齐 PHP UploadedFile::getErrorMessage() 第 82-106 行
Sourcepub fn error_code(&self) -> UploadErrCode
pub fn error_code(&self) -> UploadErrCode
获取错误码
Sourcepub fn as_file_mut(&mut self) -> &mut File
pub fn as_file_mut(&mut self) -> &mut File
访问内部 File(可变)
Trait Implementations§
Source§impl Clone for UploadedFile
impl Clone for UploadedFile
Source§fn clone(&self) -> UploadedFile
fn clone(&self) -> UploadedFile
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for UploadedFile
impl RefUnwindSafe for UploadedFile
impl Send for UploadedFile
impl Sync for UploadedFile
impl Unpin for UploadedFile
impl UnsafeUnpin for UploadedFile
impl UnwindSafe for UploadedFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.