kein sexy code aber naja keine lust das jetzt zu korrigieren, aber funktioniert bzw. prinzip ist verwendbar
PHP Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if(!empty($_POST['url'])){
$url = trim( $_POST['url']);
$html = @file_get_contents($url);
preg_match_all('/<img[^>]+>/i',$html, $result);
$img = array();
foreach( $result[0] as $img_tag)
preg_match_all('/(src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
foreach($img as $value => $key)
{
$imagepath = str_replace('"', '', $key[2][0]);
$fullpath = basename($imagepath);
if(strpos($fullpath, "empty.gif") === false && stristr($fullpath, "?")=== false){
$ch = curl_init($imagepath);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
if(strpos($rawdata,"Not Found") === false) {
if(file_exists($fullpath))
unlink($fullpath);
try {
//Bild speichern
$fp = fopen($fullpath,'x');
$check = $fp;
if(isset($check)){
fwrite($fp, $rawdata);
fclose($fp);
}
else
fclose($fp) or die("fclose");
}
catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "\n";
}
}
else
echo ("Fehler");
curl_close ($ch);
}
unset($img);
unset($value);
unset($key);
}
?>
<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">
url: <input type="text" name="url" value="" />
<input type="submit" name="submit" />
</form>
</body>
</html>
//edit: so mal unnötiges zeug entfernt. das script zieht alles innerhalb einer img src verlinkt ist. es fehlt noch eine mime_type überprüfung, aber kann man ja erweitern