get all images in URL

Discussion in 'PHP' started by gigamike, Aug 9, 2007.

  1. #1
    Guys,

    I hope you can help me. im quite stuck already :(. Im trying to get all images in a given URL. Let say www.domain.com/gallery.html. it will extract all the thumbs.

    Thanks,

    Mike
     
    gigamike, Aug 9, 2007 IP
  2. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Guys,

    by the way, what i mean here is that In a text box I'll write any website url and I want to get all of the image urls of the site.

    Thanks,

    Mike

     
    gigamike, Aug 9, 2007 IP
  3. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Submit a url, then click Get Images!

    
    <html>
    
    <body>
    
    <form action="">
    <input type="text" name="url" value="">
    <input type="submit" value="Submit URL">
    </form>
    
    <input type="button" value="Get Images!" onclick="geti();"><br>
    <textarea cols="40" rows="25"></textarea>
    
    <script type="text/javascript">
    var textarea = document.getElementsByTagName("textarea")[0];
    var images = document.getElementsByTagName("img");
    
    function geti()
    {
    	if (images.length == '')
    	{
    		alert("No images!");
    		return false;
    	}
    	
    	for (var i=0; i<images.length; i++)
    	{
    		textarea.innerHTML=textarea.innerHTML+document.getElementsByTagName("img")[i].src+'\n';
    	}
    }
    </script>
    
    <div style="display:none;">
    <?php
    	include($_GET['url'])
    ?>
    </div>
    
    </body>
    </html>
    HTML:
     
    MMJ, Aug 9, 2007 IP
  4. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Hi MMJ,

    tnx for the help. Unfortunately, it doesnt work for me.

    I started some and I used file_get_contents. Im not sure if CURL is better. Anyways here is my start-up code

    $url_handle=file_get_contents($gallery_url);
    $url_handle=str_replace("\n", ' ', $url_handle);
    $pattern="/a[\s]+[^>]*?href[\s]?=[\s\"\']+"."(.*?)[\"\']+.*?>"."([^<]+|.*?)?<\/a>/i";
    if(preg_match_all($pattern, $url_handle, $matches)){
    foreach($matches[1] as $url_image){
    $url_image_filename=trim(basename($url_image));
    list($filename, $extension)=explode(".", $url_image_filename);
    if($extension=="gif" || $extension=="jpeg" || $extension=="jpg" || $extension=="png" || $extension=="tif" || $extension=="tiff"){
    if(substr($url_image, 0, 1)=="/"){
    $valid_url_image=$url_domain_name.$url_image;
    }else{
    $valid_url_image=$url_domain_name."/".$url_image;
    }
    }
    }
    }

    it works fine to me IF the TGP or gallery has a format something like this
    Entered URL: www.domain.com/gallery.html
    <a href="original_image.gif"><img src="thumbs_image.gif"></a>

    i was able to extract www.domain.com/original_image.gif

    my problem is that if the URL or given page doesnt have an a href="image"....

    in short, im having trouble with regex. Any ideas guys to extract all

    $images="(gif|jpeg|jpg|png|tif|tiff)";

    which includes the relative or absolute URL. Like (relative url|absulute url)/$images in regex

    Thanks,

    Mike

     
    gigamike, Aug 9, 2007 IP
  5. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What do you mean it doesn't work for you?

    What did you try?

    It works fine. It just has one bug but it still works. I tried it in FF & IE.

    Do you have a link to it?
     
    MMJ, Aug 9, 2007 IP
  6. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Hi,

    i found one, this is what im trying to do

    http://demo.smartthumbs.com/st/admin/thumbscan.php?action=onefile&domain_id=1

    username: demo
    password: demo

    try any tgp or gallery and it will extract only all thumbs, very awesome logic there. Any idea how it is done, but for sure its a preg_match_all()

    Thanks,

    Mike

     
    gigamike, Aug 9, 2007 IP
  7. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Did my script work?

    Thats what my script does. :rolleyes:
     
    MMJ, Aug 9, 2007 IP
  8. RichardKnox

    RichardKnox Peon

    Messages:
    209
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It depends. Say all images are surrounded by a

    
    <div class="image"></div>
    Code (markup):
    tag. You could use an explode to get all the code inbetween that.

    Eg:

    
    
    $code = file_get_contents("http://www.domain.com/gallery.html");
    
    $step1 = explode('<div class="image"></div>', $code);
    $step2 = explode('</div>', $step1[0]);
    
    return $step2[0]
    PHP:
     
    RichardKnox, Aug 10, 2007 IP
  9. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    Hi RichardKnox,

    Thanks for the help. Ill try to think on this one.

    Thanks,

    Mike

     
    gigamike, Aug 10, 2007 IP
  10. gigamike

    gigamike Active Member

    Messages:
    165
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    Hi,

    no it didnt work :(

    Thanks,

    Mike

     
    gigamike, Aug 10, 2007 IP