user3544344 user3544344 - 2 months ago 4x
HTML Question

How to get selected file path from HTML input tag in php?

I need the selected file path(file that is being chosen by user).

For example, if I selected a file from directory F:\user\myfolder\document.docx, then this whole path should be shown.

I have used this :

$handle = $_FILES['profile']['tmp_name'];
echo $handle;

but this is giving something like this C:\xampp2\tmp\phpCECF.tmp, as this is not my current selected file path.

I have searched a lot, but can't find any solution.

Thank You.


You - as a web application - don't have access to the file system of the user. The upload form in the browser however takes the file from the user's file system and it gets uploaded to a temp location $_FILES['profile']['tmp_name'] on your server's file system.

$_FILES['profile']['tmp_name'] : The temporary filename of the file in which the uploaded file was stored on the server.

Then you'll need to use the PHP method move_uploaded_file() to rename it and store it in the final location on the server file system.

More information on PHP file upload using HTML forms: