简体   繁体   中英

viewing directory index recursively and downloading it

I'm viewing a webpage that's just a directory index. The index has folders and files, and some of the folders have folders that have folders, etc.

Is there a way to supply the url of the directory and have PHP download all the files and place them in the same order?

Yup, you can do this. Pseudocode for a function that would do this might look like the following:

function downloadLinks($url, $directory = './')
    $contents <- HTML of $url
    $links <- parse $contents and extract URLs to files and directories

    if $directory does not exist
        mkdir($directory)    

    foreach $links as $link
        if $link is a directory
            downloadLinks($url . $link, $directory . $link)
        else
            downloadFile($url, $directory . $filename)
downloadLinks('http://example.com/')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM