-1

How can i get Full path of uploaded file in php. As i uploaded a xml file and clicked on submit button full path of uploaded file will be shown on screen.

HTML

<form action="index.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" name="sub" value="Submit">
</form>

PHP

if(isset($_POST['sub']))
{
 $file = $_FILES["fileToUpload"]["name"];
 $filename = pathinfo($file);
 $st_name = $filename['filename'];
 $dir= $filename['dirname']; //directory name
 echo $dir;
}

Here as i click on submit button output should be like this...

**D://new/folder/file.xml**
Vimal
  • 1,140
  • 1
  • 12
  • 26
  • The temporary path under with the uploaded file was stored, can be found under the `tmp_name` key. But you need to _move_ it from there to a different location first of all, otherwise it will automatically get deleted when your script ends. Please go read https://www.php.net/manual/en/features.file-upload.post-method.php, it explains really all you need to know. – 04FS Nov 11 '19 at 11:37
  • Does this answer your question? [Getting complete PATH of uploaded file - PHP](https://stackoverflow.com/questions/5450713/getting-complete-path-of-uploaded-file-php) – Hitesh Tripathi Nov 11 '19 at 12:38
  • no this is not a right way – Abdul Rehman Nov 11 '19 at 12:57

1 Answers1

0

Try code below:

$uploads_dir = 'D://new/folder';

$tmp_name = $_FILES["fileToUpload"]["tmp_name"];

$name = basename($_FILES["fileToUpload"]["name"]);

$path = $uploads_dir . DIRECTORY_SEPARATOR .  $name;

move_uploaded_file($tmp_name, $path);

echo $path;
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42