php - How to download directly from one website to another -
i have piece of php code:
<?php $image_cdn = "http://ddragon.leagueoflegends.com/cdn/4.2.6/img/champion/"; $championsjson = "http://ddragon.leagueoflegends.com/cdn/4.2.6/data/en_gb/champion.json"; $ch = curl_init();` $timeout = 0; curl_setopt ($ch, curlopt_url, $championsjson); curl_setopt ($ch, curlopt_connecttimeout, $timeout); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_binarytransfer, 1); $json = curl_exec($ch); curl_close($ch); $json_array = json_decode($json, true); $champions = $json_array["data"]; foreach ($champions $championdata) { $image_url = $image_cdn.$championdata["image"]["full"]; $image = file_get_contents($image_url); file_put_contents("imgfolder/".$championdata["image"]["full"], $image); } ?>
so idea of code decode json , download images following website: http://gameinfo.na.leagueoflegends.com/en/game-info/champions/
the pictures download fine , stored folder have created on hard drive. next step is, possible me use same piece of code, download/display images onto website have created:
www.lolguides4you.co.uk website day old , have literally been messing around html coding. new both html , php if point me right direction, great!
assuming want insert images page on website, quite simple.
however, may illegal use automated scraping tool save/replicate/duplicate of images. before doing on internet.
the first step upload previous php script website. way, rather downloading images computer , trying upload them site allows save files straight directory on website.
next, can create basic php page anywhere on site:
<?php echo "images downloaded:\n"; ?>
next can use php's scandir()
function find every file in download directory:
<?php echo "images downloaded:\n"; $files = scandir('imgfolder/'); foreach($files $file) { // } ?>
finally, show each image:
<?php echo "images downloaded:\n"; $files = scandir('imgfolder/'); foreach($files $file) { echo $file . "\n"; } ?>
you use glob, allows ignore files aren't type (in case have other files in same directory:
<?php echo "images downloaded:\n"; $files = glob("imgfolder/*.jpg"); foreach($files $file){ echo $file . "\n"; } ?>
Comments
Post a Comment