0

I want to get the uploaded file path , I have created a folder in htdocs called project inside the folder there is another folder called images which holds image files and a php file called test.php which contains this code:

<?php
if(isset($_POST['submit']))
{
    $handle =$_FILES["filename"]["tmp_name"];
    echo $handle;
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
 <form action="" method="POST">
    <input type="file" name="filename">
    <input type="submit" value="Upload" name="submit">
    </form>
</body>
</html>

What I want is when I upload an image from the folder images I want to get the path images/photo.jpg but this code isnt working it says undefined index filename how can I fix it and get what I want ?

Funk Forty Niner
  • 73,764
  • 15
  • 63
  • 131
  • *"when I upload an image from the folder images I want to get the path "* - I doubt most browsers even send that information. It doesn't make sense why you'd want it, the client file system path would be useless to the server. All you need is the file data and information about the file itself (name and content type, mainly). What use would the client's path to the file be? What are you looking to *do* with that information? – David Dec 20 '18 at 17:23
  • I want it like that to upload in database so when I display in website I don't have to write myself also I don't want to upload it as blob – Johnny Adams Dec 20 '18 at 17:25
  • 1
    So you *only* want the path, not the actual file? Then you don't want an `input type="file"`, you want an `input type="text"` where the user can input the file path. You may be able to use some kind of JavaScript-based file picker component to provide a better UX to *get* that path, but if all you want is the path and not the file then ultimately all you want is a string, not a file. – David Dec 20 '18 at 17:28
  • okay thank you then – Johnny Adams Dec 20 '18 at 17:32
  • A combination of an `input type="file"` (outside the `
    ` probably) and the `FileReader` API may be what you want. Take a look at some of the code and examples here: https://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded It solves a slightly different problem than what you're trying to do, but the technologies are the same. Once the user selects a file, the `FileReader` API is probably your best bet to get details about the file on the user's file system.
    – David Dec 20 '18 at 17:34

0 Answers0