1

In PHP, I need to retrieve the path to the Downloads folder on Windows.

I'm currently using a static path, but I'd like to make the username dynamic:

$dir = 'C:\Users\ravi.kumar\Downloads';

I need the username of the system where the downloads folder exists. Any code query which can give either the Windows username or the Downloads folder path would help.

Bruno Leveque
  • 2,647
  • 2
  • 23
  • 33
Ravi Singh
  • 19
  • 7

1 Answers1

2

This works for me:

$dir = getenv('HOMEDRIVE').getenv('HOMEPATH').'\Downloads';

You can check the other available variables here: https://www.tenforums.com/tutorials/3234-environment-variables-windows-10-a.html

I hope this helps!

Bruno Leveque
  • 2,647
  • 2
  • 23
  • 33