0

When I select a file or folder through input field I am not getting the proper path in PHP.

HTML:

<input type="file" name="dirpath"  id="dirname" webkitdirectory directory multiple>

PHP code:

if(isset($_FILES['dir']))
{
    $name = file_get_contents($_FILES['dir']['tmp_name']);  
    echo '<pre>';
    print_r($name);
}

here, getting fake path like C:\fakepath\123.pdf

but actual File path I want to like this way:

path: "C:\Users\Prashan\Desktop\pdf\123.pdf"

How to find the absolute path of the file?

Jonathan
  • 1,955
  • 5
  • 30
  • 50
Sagar
  • 9
  • 3
  • 2
    That information is NEVER revealed to the client – Professor Abronsius Jul 26 '21 at 06:05
  • You just get the path of the uploaded file in `$_FILES['tmp_name']` And I cannot imagine any reasonable case where you would need the information of the path from the source machine. – Jonathan Jul 26 '21 at 10:22
  • What is proper path? The file gets uploaded on the server in the temp directory and it is your responsibility to move it to the right place – Dharman Jul 28 '21 at 13:03

1 Answers1

1

The information you are trying to get from the Uploaded file is never revealed to the client.

Also, PHP is server side programming language. It means the data and everything will is working by the server/computer and the browser has no power to edit it. It receives only data and the server will work with it (with what you coded).

If you want to open the file **without** sending it to the **server**:

This answer will help you

Dharman
  • 30,962
  • 25
  • 85
  • 135
John Doe
  • 1,401
  • 1
  • 3
  • 14