如果upload_tmp_dir没有价值...我的临时文件去哪儿了?-- 实验

php
2022-08-30 16:11:01

我真的只是在四处乱搞,学习更多关于PHP的知识,但我偶然发现了一些东西,有点让我陷入了循环。我希望我能对这个难题有所了解。

基本上,我只是试图发现上传图像的哑剧类型 - 就像主题行问的那样:如果upload_tmp_dir没有价值,那么我的临时文件最终会在哪里(在互联网上)?我应该提到,它确实告诉我我的哑剧类型!所以部分成功!

以下是我的一些规范:我正在运行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>

谢谢大家!


答案 1

它很可能使用系统的 tmp 目录。但是要真正找出答案,您应该检查 的输出。您可以将其放在文件或类似文件上,然后在浏览器中打开该文件的URL。它会告诉您所有配置值;甚至默认值。<?php phpinfo() ?>info.php

您还可以使用 sys_get_temp_dir() 找出临时目录的位置。


答案 2

我也在寻找这个答案。我在里面和里面找到了我的文件:php.ini/etc

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir = 

这似乎表明是否未指定。/tmp


推荐