11

I have uploaded a file using HTML / PHP and following is the print_r() of the $_FILES['file'] array:

Array
(
    [name] => Chrysanthemum.jpg
    [type] => application/octet-stream
    [tmp_name] => G:\xampp\tmp\php82DB.tmp
    [error] => 0
    [size] => 879394
)

As you can see above, the temp file is stored in the tmp_name directory. I need to get that directory path using PHP. How do I get it ?

Tried using sys_get_temp_dir() but this is what it returns me.

I do NOT want to get the directory from the array or from the file upload data. I want to dynamically get the php file uploads directory using a function.

C:\Users\admin\AppData\Local\Temp
hakre
  • 184,866
  • 48
  • 414
  • 792
YD8877
  • 9,852
  • 20
  • 59
  • 90
  • 2
    What do you need this path for? That directory shouldn't be any of our business on PHP level except for precisely the files that have been uploaded there. – Pekka Sep 22 '11 at 08:24

3 Answers3

26
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
xdazz
  • 154,648
  • 35
  • 237
  • 264
2

Php file upload temporary directory is a php config variable located on php.ini file.

You can get the variable config value by using ini_get function.

$path = ini_get('upload_tmp_dir'); // your code here

sepidol
  • 1,521
  • 1
  • 8
  • 5
1
$upload_dir = ini_get('upload_tmp_dir');
PeeHaa
  • 69,318
  • 57
  • 185
  • 258