How to get the PHP Uploads directory?

I uploaded the file using HTML / PHP, and the following is 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 temporary file is stored in the tmp_name directory. I need to get this directory path using PHP. How to get it?

Tried to use sys_get_temp_dir() , but this is what returns me.

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

 C:\Users\admin\AppData\Local\Temp 
+8
php
source share
3 answers
 $tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); 
+19
source share

The php file upload temporary folder is a php config variable located in the php.ini file.

You can get the value of a configuration variable using the ini_get function.

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

+2
source share
 $upload_dir = ini_get('upload_tmp_dir'); 
+1
source share

All Articles