Skip to content
PHP Logo

What are the limitations of using the dir() function to read directories specified by a URL in PHP?

The dir() function in PHP is used to read directories on the local file system, not directories specified by a URL. To read directories specified by a URL, you can use functions like file_get_contents() or cURL to fetch the directory listing and then parse the HTML content to extract the file names.

php
$url = 'http://example.com/directory/';
$html = file_get_contents($url);

// Parse the HTML content to extract file names
// For example, you can use regular expressions or a HTML parser library