List files in directory with ajax

Asked

Viewed 168 times

0

Is it possible to list the files of a directory with ajax and php? I did some research but I can’t find that combination!

$path = "/home/projetoc/public_html/filemanagerarquiv/files/";
$diretorio = dir($path);    
echo "Lista de Arquivos do diretório '<strong>".$path."</strong>':<br />";    
while($arquivo = $diretorio -> read()){
  echo "<a href='".$path.$arquivo."'>".$arquivo."</a><br />";
}
$diretorio -> close();
  • 1

    Yes it is possible! logic is in php and at the end it can hide a json for javascript to display or manipulate.

  • And how would this listing with ajax. I updated the question!

  • Instead of echo, make an assignment in an array with the link, after while send a echo json_encode($arrayDeLinks);. AI in javascript you manipulate json as you see fit, just to test a console.log(data), date is returned variable in ajax

  • 1

    Generate an array with the directories and convert to json, then just manipulate the data with Ajax.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.