[英]Is there a way to upload a file through PHP with specific “tmp_name”?
When uploading a file through PHP - The default behavior of the interpreter is to save the file in a temporary folder, with temporary name.通过 PHP 上传文件时 - 解释器的默认行为是将文件保存在临时文件夹中,并使用临时名称。
Then we will have to use the function move_uploaded_file()
in order to save it permanently.然后我们将不得不使用 function
move_uploaded_file()
来永久保存它。
If I have access to the php code- is there a way to skip the move_uploaded_file()
phase ?如果我可以访问 php 代码 -有没有办法跳过
move_uploaded_file()
阶段?
Yes and no.是和不是。 You can specify which directory to put the temporary files in, but not decide on the temporary name yourself.
您可以指定放置临时文件的目录,但不能自行决定临时名称。
Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini.
默认情况下,文件将存储在服务器的默认临时目录中,除非在 php.ini 中使用 upload_tmp_dir 指令指定了另一个位置。
So you can set upload_tmp_dir :所以你可以设置upload_tmp_dir :
The temporary directory used for storing files when doing file upload.
文件上传时用来存放文件的临时目录。 Must be writable by whatever user PHP is running as.
PHP 运行的任何用户都必须是可写的。 If not specified PHP will use the system's default.
如果未指定 PHP 将使用系统默认值。
If the directory specified here is not writable, PHP falls back to the system default temporary directory.
如果此处指定的目录不可写,则 PHP 回退到系统默认临时目录。 If open_basedir is on, then the system default directory must be allowed for an upload to succeed.
如果 open_basedir 打开,则必须允许系统默认目录才能成功上传。
However, this merely decides the directory but not the filename itself.但是,这仅决定目录,而不是文件名本身。
I think there is pretty solid reasoning why you can't do that:我认为你不能这样做的理由很充分:
/etc/shadow
on a Linux-based system and hook into system access./etc/shadow
并挂接到系统访问权限。 Furthermore, I personally don't really see any reason why using the process with move_uploaded_file()
would be bothersome.此外,我个人并不认为将进程与
move_uploaded_file()
一起使用会很麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.