<?php $url = "http://c.hiphotos.baidu.com/image/w%3D210/sign=ed30880babec8a13141a50e1c7029157/
D52a2834349b033be1a9503e17ce36d3d539bd35.gif "; function Curl_url ($url, $type =0, $timeout =30) {$msg = [' Code ' =>2100, ' status ' => ' Error ', ' msg ' => ' unknown error.
'];
$imgs = [' image/jpeg ' => ' jpeg ', ' image/jpg ' => ' jpg ', ' image/gif ' => ' gif ', ' Image/png ' => ' png ', ' text/html ' => ' html ', ' text/plain ' => ' txt ', ' ima
Ge/pjpeg ' => ' jpg ', ' image/x-png ' => ' png ', ' Image/x-icon ' => ' ico '];
if (!stristr ($url, ' http ')) {$msg [' Code ']= 2101;
$msg [' msg '] = ' URL address is incorrect! ';
return $msg;
} $dir = PathInfo ($url);
Var_dump ($dir);
$host = $dir [' dirname ']; $refer = $host. '
/';
$ch = Curl_init ($url); curl_setopt ($ch, Curlopt_referer, $refer); Forgery Source Address curl_setopt ($ch, Curlopt_returntransfer, 1)//return variable content or direct output string, 0 output, 1 return content curl_setopt ($ch, Curlopt_ Binarytransfer, 1);//In Enable CurlWhen Opt_returntransfer, return the raw (raw) output curl_setopt ($ch, Curlopt_header, 0); Output header header information 0 or 1 is curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
Timeout time $data = curl_exec ($ch);
$httpCode = Curl_getinfo ($ch, Curlinfo_http_code);
$httpContentType = Curl_getinfo ($ch, Curlinfo_content_type);
$info = Curl_getinfo ($ch);
Curl_close ($ch);
$httpCode = Intval ($info [' http_code ']);
$httpContentType = $info [' Content_Type '];
$httpSizeDownload = Intval ($info [' size_download ']);
if ($httpCode!= ') {$msg [' Code ']= 2102; $msg [' msg '] = ' URL returned incorrectly.
';
return $msg;
} if ($type >0 &&!isset ($imgs [$httpContentType]) {$msg [' Code ']= 2103; $msg [' msg '] = ' URL resource type is unknown.
';
return $msg;
} if ($httpSizeDownload <1) {$msg [' Code ']= 2104; $msg [' msg '] = ' content is not in the correct size.
';
return $msg;
} $msg [' code '] = 200;
$msg [' Status ']= ' success ';
$msg [' msg '] = ' Resource acquisition success ';
if ($type ==0 or $httpContentType = = ' text/html ') $msg [' data '] = $data;
$base _64 = Base64_encode ($data); if ($type = =1) $msg [' data '] = $base _64;
ElseIf ($type ==2) $msg [' data '] = "data:{$httpContentType};base64,{$base _64}";
ElseIf ($type ==3) $msg [' data '] = ' '; else $msg [' msg '] = ' unknown return requirement.
';
Unset ($info, $data, $base _64);
return $msg;
$msg = Curl_url ($url, 3);
if ($msg [' Status ']== ' success ') echo $msg [' data ']; Die;?>.
The output effect is as follows:
The following is a description of the partial Curl function parameters:
Curl Library Method
name description
curl_close closes a curl session
Curl_copy_handle copies all the contents and parameters of a Curl connection resource
Curl_ errno Returns a numeric number containing the current session error message
Curl_error Returns a string containing the current session error message
Curl_exec performs a curl session
Curl_ GetInfo Gets the information for a Curl connection resource handle
curl_init Initializes a curl session
Curl_multi_add_handle To add a separate curl handle resource to the Curl batch session
curl_multi_close Close a batch handle resource
curl_multi_exec resolve a curl batch
handle Curl_multi_getcontent returns the text stream of the obtained output
Curl_multi_info_read Obtain the associated transport information of the currently parsed Curl
Curl_multi_init Initializes a curl batch handle resource
Curl_multi_remove_handle removes a handle resource from the Curl batch handle resource
Curl_multi_select The sockets associated with the CURL extension, which can then is "selected"
Curl_setopt_array in the form of an array Curl Set Session parameters
curl_setopt Set session parameters for a Curl
curl_version Get Curl-related version information
curl_setopt () Parameter name Description curlopt_infilesize when you upload a file to a remote site, this option tells PHP the size of the file you uploaded.
Curlopt_verbose If you want to curl report every unexpected thing, set this option to a value other than 0.
Curlopt_header If you want to include a header in the output, set this option to a value other than 0. curlopt_noprogress If you don't PHP will display a process bar for curl transmission, set this option to a non 0 value.
Note: PHP automatically sets this option to a value other than 0, and you should only change this option for debugging purposes.
Curlopt_nobody If you don't want to include the body part in the output, set this option to a value other than 0. Curlopt_failonerror If you want PHP to be in error (HTTP code returns greater than or equal to 300), do not display, set this option to a person not 0 value.
The default behavior is to return a normal page, ignoring the code.
Curlopt_upload If you want PHP to be ready for upload, set this option to a value other than 0. Curlopt_post If you want PHP to do a regular HTTP POST, set this option to a non 0 value.
This post is an ordinary application/x-www-from-urlencoded type, most of which is used by HTML forms.
Curlopt_ftplistonly set this option to a value other than 0, PHP lists the list of directory names for FTP.
Curlopt_ftpappend set this option to a value other than 0, PHP will apply a remote file instead of overwriting it.
CURLOPT_NETRC set this option to a value other than 0, PHP will find the username and password of the remote site you want to connect to in your ~./netrc file.
Curlopt_followlocation set this option to a non 0 value (like "Location:"), the server will send it as a part of the HTTP header (note that this is recursive, PHP will send the shape as "Location:" header). Curlopt_put set this option for a non 0 value to upload a file with HTTP.
To upload this file, you must set the Curlopt_infile and Curlopt_infilesize options.
Curlopt_mute set this option to a value other than 0, PHP will be completely silent for the curl function.
Curlopt_timeout sets a long shaping number as the maximum continuation number of seconds. Curlopt_loW_speed_limit sets a long shaping number to control how many bytes are transferred.
Curlopt_low_speed_time sets a long shaping number, controlling how many seconds to transfer curlopt_low_speed_limit The specified number of bytes.
Curlopt_resume_from passes a long shaping parameter that contains the byte offset address (the start form you want to transfer to). Curlopt_sslversion passes a long parameter that contains an SSL version.
The default PHP will be determined by its own efforts, and in more security you must set it manually. Curlopt_timecondition passes a long parameter specifying how to handle the Curlopt_timevalue parameter. You can set this parameter to Timecond_ifmodsince or timecond_isunmodsince.
This is for HTTP only. Curlopt_timevalue passes a number of seconds from 1970-1-1 onwards to the present.
This time is used by the Curlopt_timevalue option as the specified value or by default timecond_ifmodsince. Curlopt_url This is the URL address you want to retrieve with PHP.
You can also set this option when initializing with the Curl_init () function.
Curlopt_userpwd passes a string in the form of a [Username]:[password] style that functions as PHP to connect.
Curlopt_proxyuserpwd passes a string in a form such as [Username]:[password] to connect to the HTTP proxy. Curlopt_range pass a range that you want to specify. It should be "XY" format, X or Y is excepted.
HTTP transmissions also support several intervals, separated by a x-y,n-m.
Curlopt_postfields passes a string of all data that is an HTTP "POST" operation.
Curlopt_referer contains a string of "REFERER" headers in the HTTP request.
Curlopt_useragent contains a string of "user-agent" headers in the HTTP request. Curlopt_ftpport passes an IP address that is used by the ftp "POST" instruction. This post instruction tells the remote server to connect to the IP address we specified.
This string can be an IP address, a host name, a network interface name (under Unix), or '-' (using the system default IP address). Curlopt_cookie passes AThe header connection that contains the HTTP cookie.
Curlopt_sslcert passes a string containing the PEM format certificate.
CURLOPT_SSLCERTPASSWD passes a password that is required to use the Curlopt_sslcert certificate. Curlopt_cookiefile A string that passes the name of a file containing cookie data.
This cookie file can be in Netscape format, or in the HTTP style header that is stockpiled in the file. Curlopt_customrequest when making an HTTP request, passing a character is used by the get or head. It is useful for delete or other operations, more pass a string of used instead of a and head when doing a HTTP request. This is useful to doing or another, more obscure, HTTP request. Note: Do not do this before confirming your server support command.
The following options require a file description (obtained by using the fopen () function) Curlopt_file This file will be the output file you place the transfer by default, stdout.
Curlopt_infile This file is the input file you sent over.
Curlopt_writeheader This file is written with the head part of your output. Curlopt_stderr This file is written with errors rather than STDERR. To get an example of a page that needs to be logged in, the current practice is to log in once every time, and the person who needs to do it improves the curlopt_autoreferer automatically sets the Referer information in the header Curlopt_binarytransfer When Curlopt_returntransfer is enabled, the fetch data is returned when Curlopt_cookiesession is enabled Curl will simply pass a session cookie, ignoring the other cookies, By default curl will return all cookies to the server.
A session cookie is a cookie that is used to determine whether a server-side session is valid.
Curlopt_crlf converts a newline character from UNIX to a carriage return line feed when enabled.
When Curlopt_dns_use_global_cache is enabled, a global DNS cache is enabled, which is thread-safe and defaults to true. Curlopt_failoneRror Displays the HTTP status code, the default behavior is to ignore HTTP information that is less than or equal to 400 curlopt_filetime when enabled, attempts to modify information in remote documents.
The resulting information is returned through the curlinfo_filetime option of the Curl_getinfo () function.
When Curlopt_followlocation is enabled, the server server returns "Location:" is recursively returned to the server in the header, using Curlopt_maxredirs to limit the number of recursive returns.
Curlopt_forbid_reuse is forced to disconnect after completing the interaction and cannot be reused.
Curlopt_fresh_connect forces a new connection to replace the connection in the cache.
When Curlopt_httpget is enabled, the HTTP method is set to get, because get is the default, so it is only used if it is modified.
Curlopt_httpproxytunnel is transmitted through the HTTP proxy when enabled.
Curlopt_mute restores all modified parameters in the Curl function to their default values.
Curlopt_returntransfer returns the information obtained by CURL_EXEC () as a file stream instead of directly outputting it.
The Curl_getinfo () function is to get information about a Curl connection resource handle, the Curl_getinfo () function has two parameters, the first argument is the curl resource handle, and the second parameter is the following constants:
The Curl_getinfo () parameter
name description
curlinfo_effective_url The last valid URL address
curlinfo_http_code The last HTTP code received
curlinfo_filetime the time when the document was remotely fetched, and if it cannot be obtained, the return value is "1"
curlinfo_total_time the time consumed by the last transfer
Curlinfo_namelookup_time The time consumed by name resolution
Curlinfo_connect_time The time it takes to establish a connection
curlinfo_ Pretransfer_time the time it uses to establish a connection to the ready transport
curlinfo_starttransfer_time the time it was used to start the connection to the transport
Curlinfo_ Redirect_time the amount of time used to redirect before the transaction transfer starts
curlinfo_size_upload the total value of uploaded data
curlinfo_size_download Total amount of Download data
curlinfo_speed_download average download speed
curlinfo_speed_upload average upload speed
curlinfo_header_ size HEADER part
curlinfo_header_out Send requested string curlinfo_request_size the size of the request with the problem in the HTTP request
Curlinfo_ssl_verifyresult Result of SSL certification verification requested by setting Curlopt_ssl_verifypeer
curlinfo_content_length_ DOWNLOAD the length of the download content read from Content-length:field
curlinfo_content_length_upload The description of the size of the upload
curlinfo _content_type the "Content-type" value of the downloaded content, NULL indicates that the server did not send a valid "Content-type:header"