php 如果upload_tmp_dir 没有价值...我的临时文件去哪里了?-- 实验
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15729353/
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
If upload_tmp_dir has no value... where do my temp files go? -- experiments
提问by Adritek
I'm really just messing around and learning more about PHP, but I stumbled upon something that kinda threw me for a loop. I'm hoping I could just get some insight on the conundrum.
我真的只是在胡闹并学习更多关于 PHP 的知识,但我偶然发现了一些让我陷入困境的东西。我希望我能对这个难题有所了解。
Basically I'm just trying to discovering mimetypes for uploaded images - and like the subject line asks: if upload_tmp_dir has no value, where (in the internets) do my temp files end up? I should mention that it does tell me my mimetypes! So partly a success!
基本上我只是想发现上传图像的 mimetypes - 就像主题行问的那样:如果 upload_tmp_dir 没有价值,我的临时文件在哪里(在互联网中)结束?我应该提到它确实告诉我我的模仿类型!所以部分成功!
And here are some of my specs: I'm running PHP 5.3+ and my upload_tmp_dir has no value - I did read another post from 2008 that suggested var_dump might help but it only returns an empty array.
这是我的一些规范:我正在运行 PHP 5.3+ 并且我的 upload_tmp_dir 没有任何价值 - 我确实阅读了 2008 年的另一篇文章,该文章建议 var_dump 可能会有所帮助,但它只返回一个空数组。
<?php
if(empty($_FILES)){
echo "nothing in files array -- ignore warning, testing only" . "<br /><br />";
}
$finfo = new finfo(FILEINFO_MIME_TYPE);
$fileContents = file_get_contents($_FILES['upload']['tmp_name']); // check tmp dir for
$mimeType = $finfo->buffer($fileContents);
echo $mimeType . "<br /><br />";
echo var_dump($_FILES) . "<br /><br />";
?>
<form action="" method="post" enctype="multipart/form-data">
<p>
<label id="upload">Select a file to upload:
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
<input type="file" id="upload" name="upload">
</label>
</p>
<p>
<input type="hidden" name="action" value="upload">
<input type="submit" value="Submit">
</p>
</form>
Thanks everyone!
谢谢大家!
回答by Michael H?rtl
It will most likely use the system's tmp directory. But to really find out you should inspect the output of <?php phpinfo() ?>
. You can put it onto a info.php
file or similar and open that file's URL in your browser. It will tell you all the configuration values; even defaults.
它很可能会使用系统的 tmp 目录。但要真正找出答案,您应该检查<?php phpinfo() ?>
. 您可以将其放入info.php
文件或类似文件中,然后在浏览器中打开该文件的 URL。它会告诉你所有的配置值;甚至默认。
You can also use sys_get_temp_dir()
to find out the location of the temp directory.
您还可以使用sys_get_temp_dir()
来找出临时目录的位置。
回答by JohnK
I was looking for this answer too. I found my php.ini
file in /etc
and inside:
我也在找这个答案。我php.ini
在/etc
里面和里面找到了我的文件:
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =
This seems to indicate /tmp
if unspecified.
这似乎表明/tmp
是否未指定。