If you need to capture files from the website, you can use the file_get_contents and fopen functions. However, when the downloaded files are set to have basic verification on the server, special processing is required.
Keywords: stream_context_create, base64_encode
<? PHP $ url = 'HTTP: // www.demo.com/img.png'#//basic verification processing $ login = 'usr'; $ pass = '000000'; $ basicsets = array (); $ basicsets ['http'] = array ('header' => 'authorization: Basic '. base64_encode ("{$ login }:{ $ pass}"); $ context = stream_context_create ($ basicsets); // 1. file_get_contents $ STR = file_get_contents ($ URL, false, $ context); file_put_contents ('. /img.png ', $ Str); // 2. fopen $ DATA = ''; $ handle = @ fopen ($ URL, 'r B ', false, $ context); While ($ handle &&! Feof ($ handle) {$ data. = @ fread ($ handle, 8192) ;}@ fclose ($ handle); $ handle =@ fopen ('. /img.png ', 'wb'); @ fwrite ($ handle, $ data); @ fclose ($ handle );