简体   繁体   中英

getimagesize - failed to open stream: Connection timed out in

In my php script in am trying to get an image from a URL, resize it, and upload it to my server. The script can be seen at http://getsharp.net/imageupload.php?admin=rene - The script is seen below (there is of course also some other PHP and HTML in it, but this is the part giving me an issue):

$admin = $_REQUEST['admin'];
$url = $_POST['uploadlink'];

    if ($_POST['filename']){
        $filename = $_POST['filename'].".jpg";
    } else {
        $urlinfo = parse_url($url);
        $filename = basename($urlinfo['path']);

        $filenamearray = explode(".", $filename);
        $filenamebase = $filenamearray[0];
        $filenamebase = substr($filenamebase, 0, 20); // max 20 characters
        $filename = $filenamebase.".jpg";

    }

    // Get new dimensions
    list($width, $height) = getimagesize($url);
    $new_width = 300;
    $ratio = $height/$width;
    $new_height = 300*$ratio;

    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);

    if(exif_imagetype($url) == IMAGETYPE_GIF){
        $image = imagecreatefromgif($url);
    }else if(exif_imagetype($url) == IMAGETYPE_JPEG){
        $image = imagecreatefromjpeg($url);
    }else if(exif_imagetype($url) == IMAGETYPE_PNG){
        $image = imagecreatefrompng($url);
    }else{
        $image = false;
    }

    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    if(is_dir("images/upload/".$admin."/")){
        // Output
        imagejpeg($image_p, "images/upload/".$admin."/".$filename);

        imagedestroy($image_p);
    }else{
        mkdir("images/upload/".$admin."/");
        // Output
        imagejpeg($image_p, "images/upload/".$admin."/".$filename);

        imagedestroy($image_p);
    }
    $URL="http://getsharp.net/imageupload.php?admin=".$admin; 

    header ("Location: $URL");

Everything is working fine, except that when I throw in a new URL it gives me the following error: Warning: getimagesize(http://buffalocomputerconsulting.com/images/computer.jpg): failed to open stream: Connection timed out in.

However, if i throw in the exact same URL right after, there is no problem, and the image is being uploaded. So every time I try a new URL the first time, it gives me the above error. How can this be?

Thanks.

  1. Your DNS resolves too slowly
  2. Your server tries a nonreplying DNS first
  3. Your server tries to connect on IPv6 first
  4. Your uplink is slow as molasses but it has a caching proxy

I am sure there are more. Try your script on another machine and see whether it changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM