Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If upload_tmp_dir has no value... where do my temp files go? -- experiments

Tags:

php

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.

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!

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

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!

like image 409
Adritek Avatar asked Mar 31 '13 12:03

Adritek


2 Answers

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.

You can also use sys_get_temp_dir() to find out the location of the temp directory.

like image 71
Michael Härtl Avatar answered Nov 19 '22 00:11

Michael Härtl


I was looking for this answer too. I found my php.ini file in /etc and inside:

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

This seems to indicate /tmp if unspecified.

like image 8
JohnK Avatar answered Nov 19 '22 00:11

JohnK