[
'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) {
$base64 = base64_encode($imageData);
$imageSrc = 'data:image/jpeg;base64,' . $base64;
echo '
';
// Check if the "download" checkbox is checked
if (isset($_POST['download']) && $_POST['download'] == 'on') {
// Save the image as download.jpeg on the server
$file = fopen('download.jpeg', 'w');
fwrite($file, $imageData);
fclose($file);
echo 'Image saved as download.jpeg on the server.';
} else {
echo 'Image not downloaded.';
}
} else {
echo 'Failed to retrieve the image.';
}
}
?>