[
'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0\r\n" .
"Referer: https://accounts.pixiv.net\r\n",
],
];
$context = stream_context_create($options);
$html = file_get_contents($url, false, $context);
$pattern = '/image" href="(.*?)"/'; //find downscaled master img (always in jpg format)
//$pattern = '/"original":"(.*?)"/'; //find original image (usually only works when logged in)
preg_match($pattern, $html, $matches);
$imageUrl = $matches[1];
echo 'Image Link: ' . $imageUrl . '
';
$imageData = file_get_contents($imageUrl, false, $context);
if ($imageData !== false) {
// Extract the filename from the URL
$filename = basename($imageUrl);
// Save the image data to a file
file_put_contents($filename, $imageData);
echo 'Image saved as: ' . $filename . '
';
} else {
echo 'Failed to retrieve the image from: ' . $url . '
';
}
}
}
?>