0

I want to select file with an input tag, but this don't return me full path of selected file(full directory).

I try this code in edge browser and return me full path of selected file but other browser can't.

this my form :

<form method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" name="submit">
</form>

and

    $filename = $_FILES["file"]["name"];
    $filedir = $_FILES["file"]["tmp_name"];

any idea?? plz help

Emad
  • 11
  • 1
  • 1
  • untill you save file to somewhere in folder the file stays in temp folder location. so i didn't get why you need temp folder path. – Alive to die - Anant Mar 20 '18 at 13:16
  • 1
    When you upload a file to the server. The server has access to the original file name, and the temporary name and location (stored on the server). **The server does not get the full directory from the client's machine**, which is what I think you are alluding to. – JustCarty Mar 20 '18 at 13:22
  • i dont need temp directory...i need directory of selected file....for example c:\text1.txt – Emad Mar 20 '18 at 13:23
  • @Emad Is that not what `tmp_name` is? Use the temporary name/location to `move_uploaded_file` – JustCarty Mar 20 '18 at 13:24

1 Answers1

0

So this is what i understand from your Question.

You need full path for the file to **open** it or work on it:

if(isset($_FILES["file"])){
   $FileData file_get_contents($_FILES["file"]["tmp_name"]);
   echo $FileData;
   //Data inside the file will be shown in the browser
}

You need "**real**" path use:

if(isset($_FILES["file"])){
   echo realpath($_FILES["file"]["tmp_name"]);
}

If you mean path from **client** **side**:

This is PHP. PHP is server side. 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
Hope i get what you want
Aidb David
  • 11
  • 6