Jump to content


php_network_getaddresses: getaddrinfo failed

  • Please log in to reply
3 replies to this topic

#1 KapaGino

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 25 September 2013 - 07:09 PM

Hi there,


I've hit a bit of a roadblock on something I've been working on, was wondering if anyone knew of a way to fix the error message:


imagecreatefromjpeg():php_network_getaddresses: getaddrinfo failed


The code I'm using is below, the script basically grabs a certain image from a set of specific urls and resizes it as close to 600x450 as it can, then saves the image/images in a zip file which the user can then download.


I should also mention that I'm currently hosting this on x10hosting, and it runs a-okay locally.


include 'zip.php';

function getImage($tags){
$count = 0;

    foreach ($tags as $tag){
        $count += 1;

        if ($count == 3){
            $old_image = $tag->getAttribute('src');
            return $old_image;

function deleteFiles($random_name){
    $images= scandir("$random_name"); //get an array of files
    unset($images[0], $images[1]);
    // loop through files
    foreach($images as $image){
        unlink("$random_name/$image"); // delete each file


$omitted_urls = [];

if (isset($_POST['submit'])){
    $start_time = time();

    $urls = $_POST['urls']; // take inputted urls
    $urls = explode("\r\n", $urls); // break them up by a carriage return/new line into array

    $names = $_POST['names']; // take inputted names
    $names = explode("\r\n", $names); // break them up by a carriage return/new line into array

    $random_name = "pics".rand(0,1000); // create a random folder name
    if (!is_dir("$random_name")){
        mkdir("$random_name", 0777);

    // for each url
    for($i=0; $i < count($urls); $i++){

        @$html = file_get_contents($urls[$i]); // get the contents of the url

        $doc = new DOMDocument();
        @$doc->loadHTML($html); // load up the html file
        $tags = $doc->getElementsByTagName('img'); // look for all img tags
        $count = 0;

        $special_chars = array('\\','/',':','*','?','"','<','>','|'); // look for any special characters

        $names[$i] = str_replace($special_chars, "", $names[$i]); // replace them with ""
        $names[$i] = substr($names[$i], 0, 50); // truncate anything over 50 characters

        if($old_image = imagecreatefromjpeg(getImage($tags))){ // create the old image

            echo "The src is ".getImage($tags)."<br>";

            $old_width = imagesx($old_image);  // get the width of the old image
            $old_height = imagesy($old_image); // get the height of the old image

            $ratio_orig = $old_width/$old_height; // work out the ratio of the image

            $new_width = 600; $new_height = 450;

            if ($new_width/$new_height > $ratio_orig){
                $new_width = $new_height*$ratio_orig;
            } else {
                $new_height = $new_width/$ratio_orig;

            $new_image = imagecreatetruecolor($new_width, $new_height); // creates a black image to represent size
            imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); // copy over old image to fit new image

            imagejpeg($new_image, "$random_name/".$names[$i].'.jpg'); // create the new image file
            imagedestroy($new_image); // destroy the image file
            $time = time()- 3600; // find out the time

            } else {
                $omitted_urls[] = $names[$i];


    $final_time =  time() - $start_time; // final time is the current time take the starting time
    $final_time = date("i:s", $final_time); // time taken


<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8" />
        <title>EGI Research - Resize and Extract Images</title>
        <link href="/RESEARCH/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        <link href="css/style.css" rel="stylesheet"/>

        <script src="/RESEARCH/bundles/modernizr?v=rGcoDow97GYrNMSwHq7xCCjlcB3UIY4_OhPRc6BBSQA1"></script>

            <div class="content-wrapper">
        <div id="body">
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>URL Image Extractor & Resizer</h1>

            <?php if(isset($_POST['submit'])){
            printf("<br><b> %s images were downloaded and resized in %s seconds </b><br><br>", count(scandir($random_name))-2, $final_time);

            if (count($omitted_urls) > 0){
                foreach($omitted_urls as $omitted_url){
                    echo "$omitted_url was omitted<br>";

            echo "<a href='$random_name.zip'>Click here to download images</a>";

            <section class="content-wrapper main-content clear-fix">

<form action="" id="UploadForm" method="post"><div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li

</ul></div>    <ol class="round">
        <li class="one">
            <p>Enter a set of EGi URLS</p>
            <textarea name="urls" rows="4"></textarea>
        <li class="two">
            <h5>File Names</h5>
            Enter a set of unique identifiable File Names
            <textarea name="names" rows="4"></textarea>
            <input type="submit" value="Extract & Resize" name="submit"/><a href="index2.php">Clear Form</a>

            <div class="content-wrapper">
                <div class="float-left">
                    <p>&copy; 2013 - Reed Business Information Ltd.</p>


Thanks for any of your know how.

Edited by KapaGino, 25 September 2013 - 07:13 PM.

#2 requinix

  • Administrators
  • Lazy Administrator
  • 9,367 posts
  • LocationWA

Posted 25 September 2013 - 08:15 PM

What is the URL (the actual value) that you're passing to imagecreatefromjpeg()?
The Reimann Zeta Function Trolley Problem | "Summer is when I, the great ice fairy, can show my true power!"

#3 KapaGino

  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 26 September 2013 - 08:21 AM

The urls themselves would look like this:



Edited by KapaGino, 26 September 2013 - 08:24 AM.

#4 mac_gyver

  • Staff Alumni
  • Staff Alumni
  • 4,071 posts

Posted 26 September 2013 - 06:44 PM

1) the @ error suppressors you have in your code are probably hiding related errors, that the web host doesn't permit reading external urls. you need to remove all the @ error suppressors and have php's error_reporting set to E_ALL so that you know everything that is not working in the code.


2) have you echoed what getImage($tags) does return so that you know it is an actual complete expected value?

multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users