Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.9 kB
2
Indexable
Never
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $fileName = $_FILES['file']['name'] ?? '';
    echo json_encode(scandir('1'));
    return;
    move_uploaded_file($_FILES['file']['tmp_name'], "1/$fileName");
}
var_dump(scandir('1'));
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=
    , initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <form id=form action="" method="post" enctype="multipart/form-data">
        <p><label for="choose file:">choose file:</label></p>
        <p><input type="file" name="file" placeholder="Choose File..."></p>
        <p><input type="submit" value="submit"></p>
    </form>
    <table id="table">
        <tr>
            <th>fileName</th>
        </tr>
    </table>

    <script src="jquery.js"></script>
    <script>
        $('#form').on('submit', function(event) {
            event.preventDefault();
            var data = $(this).serialize();
            var url = "fileManager.php";
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function(response) {
                    // console.log(response)
                    var responseDecode = JSON.parse(response);
                    console.log(responseDecode);
                    for(i of responseDecode){
                        console.log(i)
                        if(i=='.' || i=='..'){
                            continue;
                        }else{
                          $('#table').append('<tr><td>'+i+'</td></tr>')  
                        }
                        
                    }
                }
            })
        })
    </script>
</body>

</html>