<?php
set_time_limit(0);
function SaveCurlPage ($url, $save_file, $cookie) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_REFERER, $url); // need to fake a referer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
$tmp = curl_exec ($ch);
if(curl_errno($ch) == 0) {
file_put_contents($save_file, $tmp);
}
curl_close ($ch);
}
$url = 'not allowed (pinterest popular url)';
$agent= "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$cookiefile = tempnam("ciastka", uniqid());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
$result = curl_exec($ch);
curl_close ($ch);
$wzor = '/media-cdn.pinterest.com\/upload\/([A-Za-z0-9_]*).jpg/';
preg_match_all($wzor, $result, $wynik);
$images = $wynik[1];
foreach ($images as $image) {
$image .= '.jpg';
$path = 'not allowed to pust urls' . $image;
if (!file_exists($image)) {
SaveCurlPage($path, $image, $cookiefile);
}
}
?>