php 上传时PHP将临时文件保存在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3817360/
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
Where does PHP save temporary files during uploading?
提问by powerboy
I am using XAMPP on Windows. By printing $_FILES["file"]["tmp_name"]
, it seems that the temporary file was saved at C:\xampp\tmp\phpABCD.tmp. But I cannot see it on the filesystem of the server. However, the file can be moved or copied via move_uploaded_file()
, rename()
, or copy()
. So where does PHP actually save temporary files during uploading?
我在 Windows 上使用 XAMPP。通过打印$_FILES["file"]["tmp_name"]
,似乎临时文件保存在 C:\xampp\tmp\phpABCD.tmp。但是我在服务器的文件系统上看不到它。但是,文件可以移动或复制通过move_uploaded_file()
,rename()
或copy()
。那么PHP在上传过程中实际上将临时文件保存在哪里呢?
回答by Matthew
It saves it at the path specified in $_FILES["file"]["tmp_name"]
, but deletes it after the script is done executing. It's up to you to move the file elsewhere if you want to preserve it.
它将其保存在 中指定的路径中$_FILES["file"]["tmp_name"]
,但在脚本执行完成后将其删除。如果您想保留文件,则由您将文件移到别处。
回答by bpeterson76
Its specified in upload_tmp_dir
in your php.ini file. It is deleted by the system automatically after use.
它upload_tmp_dir
在您的 php.ini 文件中指定 。使用后由系统自动删除。
回答by Jesse
You can check where php is currently saving your temp files $_FILES["file"]["tmp_name"]
by printing
您可以files $_FILES["file"]["tmp_name"]
通过打印来检查 php 当前保存您的临时文件的位置
sys_get_temp_dir()
回答by Mamta
Use move_uploaded_file(file, path)
, specify the file and the path where you want to store the file.
使用move_uploaded_file(file, path)
,指定文件和要存储文件的路径。
A copy of that file is created and gets stored.
创建并存储该文件的副本。
回答by poke
php stores all temporary files, that includes uploaded files, in the temporary files directory as specified in the php.ini. Note that for uploads, those files might be removed as soon as the script the file was uploaded to was terminated (so unless you delay that script, you probably won't see the uploaded file). Another reason might be that the file is simply hidden on the file system.
php 将所有临时文件(包括上传的文件)存储在 php.ini 中指定的临时文件目录中。请注意,对于上传,一旦文件上传到的脚本终止,这些文件可能会被删除(因此除非您延迟该脚本,否则您可能看不到上传的文件)。另一个原因可能是该文件只是隐藏在文件系统中。
So if you want to see the file, you might want to make sure you see all hidden files in the explorer and delay the script as long as you need to find the file.
因此,如果您想查看该文件,您可能需要确保在资源管理器中看到所有隐藏文件,并在需要查找文件时延迟脚本。
回答by brian_d
from http://www.php.net/manual/en/features.file-upload.php#93602, "...the uploaded file will inherit the permissions of the directory specified in the directive upload_tmp_dir
of php.ini
. If this directive isn't set, the default of C:\Windows\Temp is used..."
来自http://www.php.net/manual/en/features.file-upload.php#93602,“...上传的文件将继承指令upload_tmp_dir
中指定目录的权限php.ini
。如果该指令不是' t 设置,使用默认的 C:\Windows\Temp..."
回答by lastactionseo
Note that the file is saved binary in $_FILES["file"]["tmp_name"]
, so you may open it maybe with file_get_contents
if it is an image or something like this...
请注意,该文件以二进制格式保存$_FILES["file"]["tmp_name"]
,因此您可以打开它,file_get_contents
如果它是图像或类似的东西...