www.webdeveloper.com
Results 1 to 2 of 2

Thread: display image from url

Hybrid View

  1. #1
    Join Date
    Jun 2014
    Posts
    1

    display image from url

    I am having trouble with displaying an image from a url. In the following code if I echo out $test I get the url of the image. However, in the current code I am trying to display the image, but the only thing that gets displayed is a small broken image in the upper left. The images I am trying to display are not located on my server.
    PHP Code:
    $html file_get_contents($website.$criteria); 

    $dom = new DOMDocument;

    @
    $dom->loadHTML($html);

    $links $dom->getElementsByTagName('img');

    foreach (
    $links as $link){
        
    $test $link->getAttribute('src');
        echo 
    file_get_contents($test);


  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,392
    Well, you can't display more than one image per HTTP request, so simply looping over the list of image URLs and dumping their contents into the output buffer is not going to work (assuming your PHP config even has the allow_url_fopen setting enabled).

    Why not just output your own <img> tags at that point using the URLs as the src value? (Although I'm guessing that the value of $test may not always be a fully qualified URL, so that might not work without some additional code to analyze it and add the "http://domain/" part, and possibly the path, as well.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles