cURL is a great tool to help you connect to remote web sites ,you can also use this for download image from web or binary file like pdf,psd,doc,zip with curl. Google is using this technique to get all web images from different web pages .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php // Example 003 // Download Image (Binnary File) // Copyright http://scriptime.blogspot.in $url = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs6cSpV0C_vNMgR-Cy3oByY-C3d1N-8kb1lMyh986hdR-Xa9CelJ6jC7j_24BHWdzwqqAS4PDGgHsPcytr6ja0G_qtg-ECLbf906MO5jHbuIF9YCmdy80x4CUCtz0TRMtkD3NsR_Rh_fgV/s1600/php-curl.png"; // URL to Download Image $ch = curl_init(); // Initialize a CURL session. curl_setopt($ch, CURLOPT_URL, $url); // Pass URL as parameter. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return stream contents. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); // We'll be returning this transfer, and the data is binary $data = curl_exec($ch); // // Grab the jpg and save the contents in the //$data variable curl_close($ch); // close curl resource, and free up system resources. // Set the header to type image/jpeg, since that's what we're // displaying header("Content-type: image/jpeg"); echo $data; // Print stream contents. ?>
|
0 comments:
Post a Comment