-3

In PHP We can do like this to view files inside a folder:

$dir    = '/var/www/';
$files1 = scandir($dir, 1);
print_r($files1);

But I want $dir depends on user input on html front end, so user may get files inside folder they choose.

braaterAfrikaaner
  • 1,072
  • 10
  • 20
AWinx
  • 11
  • 1
  • 3
  • You would need to make use of AJAX to `POST` the user's decision as a variable that gets piped out to the PHP code. See [**this question**](https://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php). – Obsidian Age Feb 22 '18 at 02:10
  • @ObsidianAge, you don't need AJAX to perform a `POST`! – Simon MᶜKenzie Feb 22 '18 at 02:40
  • You don't *need* it, but considering the HTML is not provided, you can't be sure there's a `
    ` that's set up correctly. And if you want to do it without a page refresh you need AJAX.
    – Obsidian Age Feb 22 '18 at 02:42

1 Answers1

-1

Front End To accept the path you can use either input type="text" or input type="file"

<?php
 if(isset($_REQUEST["dir_path"]))
 {
    $dir=$_REQUEST["dir_path"];//path specified in the html form
    $files1 = scandir($dir, 1);

    print_r($files1);
 }
?>
Hp_issei
  • 579
  • 6
  • 18
  • I know how to receive in the back-end. What i need is how to post 'dir-path' in front-end. – AWinx Feb 22 '18 at 14:07