0

Im building a photo album application where when you upload a picture it gets saved in a photos directory of my XAMPP server. Now I need to access the names of the files of those photos from the photos directory so that I can show them again. How to do this with javascript?

<?php 
    if(isset($_FILES['image'])){
        $error = arraY();
        $file_name = $_FILES['image']['name'];
        $file_size = $_FILES['image']['size'];
        $file_tmp = $_FILES['image']['tmp_name'];
        $file_type = $_FILES['image']['type'];
        $hello = explode('.',$_FILES['image']['name']);
        $hello2 = end($hello);
        $file_ext = strtolower($hello2);
        $extensions = array('jpeg','jpg','png');
        if(in_array($file_ext,$extensions)==false){
            $error[] = "Please choose the image which has the extension as jpeg,jpg,png";
        }
        if(empty($error) == true){
            move_uploaded_file($file_tmp,"images/".$file_name);

        }
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h3>Image Upload</h3>
    <form action="album.php" method="POST" enctype="multipart/form-data" id="form">
        <input type="file" name="image" id="image">
        <input type="submit" value="Upload">
    </form>
    <ul class="photoalbum"></ul>
</body>
</html>
Lurking
  • 21
  • 7
  • This won't be possible with Javascript alone. In your case you will need to retrieve a list of files using PHP and provide that data through your HTML for processing by Javascript. – Ian Brindley Oct 26 '21 at 14:36
  • Can you tell me how to do that with PHP – Lurking Oct 26 '21 at 14:49
  • This should help you https://stackoverflow.com/questions/24980967/find-images-with-certain-extensions-recursively – Ian Brindley Oct 26 '21 at 15:19

0 Answers0