I want to create a script where you enter a url and it gets the images from the url like in facebook, and you can choose which image you want.
I don't use facebook, so I don't know how it is done there, but anyway - what's your question? Do you need to extracrt all image urls from that page or you don't know how to download image from remote host or what?
I want to extract the links to all the images on a page, after I enter the url of a page. For example if I enter: http://www.google.com I want the script to extract all of the images on the page, and when when I click on an image, it lets me choose that image url as one of the text fields on the page.
Try this. This is for 1 image, you can download as many as needed. The array below will be lost once page changes, so save to database, or some file instead. You can also get the image extension by exploding the url. I just typed .jpg <?php $a= array(); if(isset($_POST['submit'])){ $u= $_POST['u']; //check here if it's a valid url, then download $c= file_get_contents($u); $name= md5(time()). '.jpg'; $a[]=$name; echo '<h1> Select image below </h1>'; foreach($a as $v){ echo '<a href="select.php?f='. $v. '"><img src="'. $v. '"></a>'; } } print ' <form action="script.php" method="post"> URL: <input type="text" name="u"> <input type="submit" name="submit" value=" get now"> </form> '; ?>
Well, $page = file_get_contents($_GET['url']); PHP: will load remote page, passed as url param into $page variable preg_match_all('/<img.+?src="(.+?)"/', $page, $result, PREG_PATTERN_ORDER); $result = $result[1]; PHP: will extract all image urls in $result variable Note, that image url may be a relative - so you have to prepend it with hostname or maybe path. That's genereally the beginnning. You make full image path and display these image. A little bit of javascript like <img onclick="showPath('');/> HTML: and its ready
thanks, I have got the images path on the page, how do I make the script run after the url is typed in do I use javascript and something like onfocus?
Is there a way to sort the images e.g. based on filesize? I am not sure how facebook do it, but it only brings up 4 big images from the site, instead of all of them.