13

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
  • 193,403
  • 52
  • 435
  • 836
YD8877
  • 10,401
  • 20
  • 64
  • 92
  • 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

30
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
xdazz
  • 158,678
  • 38
  • 247
  • 274
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,681
  • 1
  • 9
  • 5
1
$upload_dir = ini_get('upload_tmp_dir');
PeeHaa
  • 71,436
  • 58
  • 190
  • 262