Listing files in a directory

I am trying to list files in a directory I names jss by putting an index.php script in the same folder.
Unfortunately, I have not been able to succeed in doing this but got the error messages shared below after the main script used.
Any help will be appreciated.
Here is the script I used:

<?php if ($_POST['submit digitallib/classnotes/jss/']) { copy($_FILES['file']['tmp_name'], $_FILES['file']['name']); } ?> jss <?php $dir=opendir('digitallib/classnotes/jss/'); $files=array(); while (($file=readdir($dir)) !== false) { if ($file != "." and $file != ".." and $file != "index.php") { array_push($files, $file); } } closedir($dir); sort($files);


<?php function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); return $data; } foreach ($files as $file){ $html = file_get_contents_curl("digitallib/classnotes/jss/$file"); //parsing begins here: $doc = new DOMDocument(); @$doc->loadHTML($html); $nodes = $doc->getElementsByTagName('jss'); //get and display what you need: $title = $nodes->item(0)->nodeValue; $metas = $doc->getElementsByTagName('meta'); if ($title !="403 Forbidden"){ echo "$title". '

';} } ?>

Here is the error I got:
Warning : Undefined array key “submit digitallib/classnotes/jss/” in C:\xampp\htdocs\digitallib\classnotes\jss\index.php on line 2

Warning : opendir(digitallib/classnotes/jss/): The system cannot find the path specifi (code: 3) in C:\xampp\htdocs\digitallib\classnotes\jss\index.php on line 13

Warning : opendir(digitallib/classnotes/jss/): Failed to open directory: No such file or directory in C:\xampp\htdocs\digitallib\classnotes\jss\index.php on line 13

Fatal error : Uncaught TypeError: readdir(): Argument #1 ($dir_handle) must be of type resource or null, bool given in C:\xampp\htdocs\digitallib\classnotes\jss\index.php:15 Stack trace: #0 C:\xampp\htdocs\digitallib\classnotes\jss\index.php(15): readdir(false) #1 {main} thrown in C:\xampp\htdocs\digitallib\classnotes\jss\index.php on line 15

Your IF check isnt checking for the existance of the key, it’s checking the value, which doesnt exist. array_key_exists

The directory you have specified does not exist. Note that opendir is a filesystem reference, not a URL reference.

This is because opendir failed.

Thanks for the explanation. But what can I do to solve the problem?
I am not good in php.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.