php name 和 tmp_name 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37008227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between name and tmp_name
提问by James Chen
Hi I tried to search online but really could not find it.
So what is the difference between $_FILES['file']['name']
and $_FILES['file']['tmp_name']
, or what is the $_FILES['file']['tmp_name']
exactly?
嗨,我试图在网上搜索,但真的找不到。那么$_FILES['file']['name']
和之间有什么区别$_FILES['file']['tmp_name']
,或者究竟是$_FILES['file']['tmp_name']
什么?
According to http://php.net/manual/en/features.file-upload.post-method.php,
根据http://php.net/manual/en/features.file-upload.post-method.php,
$_FILES['userfile']['name'] The original name of the file on the client machine.
$_FILES['userfile']['tmp_name'] The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES['userfile']['name'] 客户端计算机上文件的原始名称。
$_FILES['userfile']['tmp_name'] 服务器上存储上传文件的临时文件名。
So what is the difference between the temporary filename and original filename?
那么临时文件名和原始文件名有什么区别呢?
Thank you
谢谢
采纳答案by Mukesh Ram
Your file will temporary store on this path $_FILES['image_path']['tmp_name']
. so when you move it will be remove from temp folder to your folder. If you use copy command instead of move_uploaded_file
then your temp file will be stay in your server's temp folder. you can search file name in there.
您的文件将临时存储在此路径上 $_FILES['image_path']['tmp_name']
。因此,当您移动时,它将从临时文件夹中删除到您的文件夹中。如果您使用 copy 命令而不是move_uploaded_file
那么您的临时文件将保留在您服务器的临时文件夹中。你可以在那里搜索文件名。
回答by Reza Baradaran Gazorisangi
$_FILES['file']['tmp_name']
Provides the name of the file stored on the web server's hard disk in the system temporary file directory, unless another directory has been specified using the upload_tmp_dirsetting in your php.inifile. This file is only kept as long as the PHP script responsible for handling the form submission is running. So, if you want to use the uploaded file later on (for example, store it for display on the site), you need to make a copy of it elsewhere.
在系统临时文件目录中提供存储在 Web 服务器硬盘上的文件的名称,除非使用php.ini文件中的upload_tmp_dir设置指定了另一个目录。只有在负责处理表单提交的 PHP 脚本运行时才会保留此文件。因此,如果您想稍后使用上传的文件(例如,将其存储以在网站上显示),您需要在其他地方制作它的副本。
To do this you can use the move_uploaded_file()function which moves an uploaded file from its temporary to permanent location. Please note that you'd best use move_uploaded_file()over functions like copy()and rename()for this purpose because it performs additional checks to ensure the file was indeed uploaded by the HTTP POST request.
为此,您可以使用move_uploaded_file()函数将上传的文件从其临时位置移动到永久位置。请注意,您最好为此目的使用move_uploaded_file() 而不是copy()和rename()等函数, 因为它会执行额外的检查以确保文件确实是由 HTTP POST 请求上传的。
$_FILES['file']['name']
Provides the name of the file on the client machine before it was submitted.If you make a permanent copy of the temporary file, you might want to give it its original name instead of the automatically-generated temporary filename that's described above.
在提交文件之前提供客户端计算机上的文件名。如果您制作临时文件的永久副本,您可能希望为其提供原始名称,而不是上述自动生成的临时文件名。
So all in all:
所以总而言之:
$_FILES["file"]["name"] //stores the original filename from the client
$_FILES["file"]["tmp_name"] //stores the name of the temporary file
Hope it helps!
希望能帮助到你!
回答by Learner
tmp_name
is the temporary name of the uploaded file which is generated automatically by php, and stored on the temporary folder on the server.
tmp_name
上传文件的临时名称,由php自动生成,存放在服务器的临时文件夹中。
name
is the original name of the file which is store on the local machine.
name
是存储在本地计算机上的文件的原始名称。