Home >Backend Development >PHP Tutorial >Share a complete list of commonly used PHP tools in your own projects, share a complete list of PHP tools_PHP Tutorial
Share a complete list of commonly used PHP tools in your own projects, share a complete list of PHP tools_PHP Tutorial
WBOYOriginal
2016-07-12 08:54:03862browse
Share a complete list of commonly used PHP tools in your own projects, share a complete list of PHP tools
* @param string $url The absolute url of the image
* @param string $filepath The full path of the file (such as /www/images/test). This function will automatically determine the suffix name of the image based on the image URL and http header information
* @param string $filename The name of the file to be saved (excluding extension)
* @return mixed Returns an array describing the image information if the download is successful, false if the download fails
*/
static public function downloadImage($url, $filepath, $filename) {
//Header information returned by the server
$responseHeaders = array();
//Original picture name
$originalfilename = '';
//The suffix name of the picture
$ext = '';
$ch = curl_init($url);
//Set the value returned by curl_exec to include the HTTP header
curl_setopt($ch, CURLOPT_HEADER, 1);
//Set the value returned by curl_exec to include Http content
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Set the page after crawling jump (http 301, 302)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Set the maximum number of HTTP redirects
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
//Data returned by the server (including http header information and content)
$html = curl_exec($ch);
//Get relevant information about this crawl
$httpinfo = curl_getinfo($ch);
curl_close($ch);
if ($html !== false) {
// Separate the header and body of the response. Since the server may use 302 jumps, the string needs to be separated into 2 substrings with the number of jumps
🎜>
//The penultimate paragraph is the http header of the server’s last response
$header = $httpArr[count($httpArr) - 2];
//The penultimate paragraph is the content of the server’s last response
* @param string $string Original text or cipher text
* @param string $operation operation (ENCODE | DECODE), the default is DECODE
* @param string $key key
* @param int $expiry Ciphertext validity period, valid when encrypted, unit seconds, 0 means permanent validity
* @return string The processed original text or the cipher text processed by base64_encode
*
* @example
*
* $a = authcode('abc', 'ENCODE', 'key');
* $b = authcode($a, 'DECODE', 'key'); // $b(abc)
*
* $a = authcode('abc', 'ENCODE', 'key', 3600);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn