Php curl upload, download, https login implementation code, curlhttps
1. Download curl
$ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, "ftp: // 127.0.0.1/downtest.txt"); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_TIMEOUT, 300); // set the username and password curl_setopt ($ ch, CURLOPT_USERPWD, "yuejide: 123456 "); $ outfile = fopen ("test.txt", "wb"); curl_setopt ($ ch, CURL_FILE, $ outfile); $ rtn = curl_exec ($ ch); fclose ($ outfile ); if (! Curl_errno ($ ch) {echo $ rtn;} else {echo 'curl error'. curl_errno ($ ch);} curl_close ($ ch );
2. curl upload
$ Ch = curl_init (); $ localfile = "ftp01.php"; $ fp = fopen ($ localfile, 'R'); curl_setopt ($ ch, CURLOPT_URL, "ftp: // 127.0.0.1/ftp01_upload.php "); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, expires, 1); curl_setopt ($ ch, CURLOPT_TIMEOUT, 300 ); // set the username and password curl_setopt ($ ch, CURLOPT_USERPWD, "yuejide: 123456"); curl_setopt ($ ch, CURLOPT_UPLOAD, 1); curl_setopt ($ ch, CURLOPT_INFILE, $ fp); curl _ Setopt ($ ch, CURLOPT_INFILESIZE, filesize ($ localfile); $ rtn = curl_exec ($ ch); fclose ($ fp); if (! Curl_errno ($ ch) {echo "upload successfully";} else {echo 'curl _ error'. curl_error ($ ch);} curl_close ($ ch );
3. curl https Logon
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.baidu.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); date_default_timezone_set('PRC'); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); $output = curl_exec($ch); curl_close($ch); echo $output;
The above is the implementation method for uploading, downloading, and https login in php curl. For more information, see.