-4

I have an HTML image tag with the source blank. The source will change based on input type file when the user uploads an image. So how do I get the image source? I can't hardcode the source as it will change based on what the user selects.So i want to retrieve the image src based on the file user has selected. Here are the codes i used:

i want to get the image directory by retrieving image src so i can check if there's an XML file created in the folder which has the same name as the image. thank you

PandaB3ar
  • 45
  • 10

1 Answers1

0

I believe the PHP code you are specifically asking for is

$_FILES["fileToUpload"]["name"]

However, take a look at the tutorial from w3schools.

HTML upload form

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

Php uploader

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
?>
J.A.P
  • 565
  • 5
  • 13