Created
November 3, 2016 12:33
-
-
Save davit312/94aa2e3fe4e0705b11318983675d0696 to your computer and use it in GitHub Desktop.
Image downloader for Gurgen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!empty($_GET['url'])): | |
$cnt = file_get_contents($_GET['url']); | |
if(empty($cnt)) | |
exit; | |
else | |
$cnt = substr($cnt,strpos($cnt,'<ul>'),strpos($cnt,'</ul>')-strpos($cnt,'<ul>')+4); | |
endif; | |
if(!empty($cnt)): | |
$a = array(); | |
while($i = strpos($cnt,'.jpg')){ | |
$img = substr($cnt,strpos($cnt,'//'),$i-strpos($cnt,'//')+4); | |
$cnt = substr($cnt,$i+5); | |
$a[] = 'http:'.$img; | |
} | |
endif; | |
if(!empty($a)){ | |
if(!empty($_GET['zip'])){ | |
$file = 'img'.rand().'.zip'; | |
$zip = new ZipArchive; | |
$res = $zip->open($file, ZipArchive::CREATE); | |
foreach($a as $i){ | |
$li = file_get_contents($i); | |
$zip->addFromString(basename($i),$li); | |
} | |
$zip->close(); | |
header('Content-Type: application/zip'); | |
header('Content-Length: ' . filesize($file)); | |
header('Content-Disposition: attachment; filename="'.$file.'"'); | |
readfile($file); | |
unlink($file); | |
exit; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>List.am Download</title> | |
</head> | |
<body> | |
<form action=""> | |
<input name="url" type="text"> | |
<input type="submit"> | |
<input type="checkbox" name="zip">Get zip <br> | |
</form> | |
<?php if(!empty($a)){ | |
foreach($a as $i):?> | |
<a href="<?=$i?>"><?=$i?></a> | |
<?php endforeach; | |
} ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment