简体   繁体   中英

getimagesize() error: “failed to open stream: No such file or directory”

i have that problem and i don't know what can i do?

Here is my script :

<?php

include('../include/cfg.php');

if($approval_system == 1) { $ap = 1; } else { $ap = 0; }

$path = "../uploads/";

function resize_img($url, $filename, $ext_p) {
    $max_width = 613;
    $max_height = 2000;
    $destination = '../uploads';
    $quality = '100';
    $source_pic = ''.$url.'.jpg';

    if($ext_p == 'jpg') { $src = @imagecreatefromjpg($destination.'/'.$source_pic); }
    if($ext_p == 'png') { $src = @imagecreatefrompng($destination.'/'.$source_pic); }
    if($ext_p == 'gif') { $src = @imagecreatefromgif($destination.'/'.$source_pic); }
    if($ext_p == 'jpeg') { $src = @imagecreatefromjpeg($destination.'/'.$source_pic); }

    list($width,$height)=@getimagesize($destination.'/'.$source_pic);

    $x_ratio = $max_width / $width;
    $y_ratio = $max_height / $height;

    if( ($width <= $max_width) && ($height <= $max_height) ){
        $tn_width = $width;
        $tn_height = $height;
    } elseif (($x_ratio * $height) < $max_height){
        $tn_height = ceil($x_ratio * $height);
        $tn_width = $max_width;
    } else {
        $tn_width = ceil($y_ratio * $width);
        $tn_height = $max_height;
    }

    $tmp=@imagecreatetruecolor($tn_width,$tn_height);
    @imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
    $destination_pic = ''.$destination.'/'.$filename.'.jpg';
    @imagejpeg($tmp,$destination_pic,$quality);
    @imagedestroy($src);
    @imagedestroy($tmp);
}

function resize_thumb($url, $filename, $ext_p) {
    $max_width = 170;
    $max_height = 2000;
    $destination = '../uploads';
    $quality = '100';
    $source_pic = ''.$url.'.jpg';

    if($ext_p == 'jpg') { $src = @imagecreatefromjpg($destination.'/'.$source_pic); }
    if($ext_p == 'png') { $src = @imagecreatefrompng($destination.'/'.$source_pic); }
    if($ext_p == 'gif') { $src = @imagecreatefromgif($destination.'/'.$source_pic); }
    if($ext_p == 'jpeg') { $src = @imagecreatefromjpeg($destination.'/'.$source_pic); }

    list($width,$height)=@getimagesize($destination.'/'.$source_pic);

    $x_ratio = $max_width / $width;
    $y_ratio = $max_height / $height;

    if( ($width <= $max_width) && ($height <= $max_height) ){
        $tn_width = $width;
        $tn_height = $height;
    } elseif (($x_ratio * $height) < $max_height){
        $tn_height = ceil($x_ratio * $height);
        $tn_width = $max_width;
    } else {
        $tn_width = ceil($y_ratio * $width);
        $tn_height = $max_height;
    }

    $tmp=@imagecreatetruecolor($tn_width,$tn_height);
    @imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
    $destination_pic = ''.$destination.'/'.$filename.'.jpg';
    @imagejpeg($tmp,$destination_pic,$quality);
    @imagedestroy($src);
    @imagedestroy($tmp);
}

$valid_formats = array("jpg", "png", "gif", "jpeg", "JPG", "PNG", "GIF", "JPEG");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {

    $name = $_FILES['photoimg']['name'];
    $size = $_FILES['photoimg']['size'];

    if(strlen($name)) {

        list($txt, $ext) = explode(".", $name);
        if(in_array($ext,$valid_formats)) {

            if($size<(1024*2024)) {

                $photo_n = md5(rand(0,999999999999999));
                $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
                $tmp = $_FILES['photoimg']['tmp_name'];
                if(move_uploaded_file($tmp, $path.$photo_n.'.jpg')) {

                    if($_FILES['photoimg']['type']=='image/png') { $ext_p = 'png'; }
                    if($_FILES['photoimg']['type']=='image/jpg') { $ext_p = 'jpg'; }
                    if($_FILES['photoimg']['type']=='image/gif') { $ext_p = 'gif'; }
                    if($_FILES['photoimg']['type']=='image/jpeg') { $ext_p = 'jpeg'; }

                    resize_img($photo_n,$photo_n.'_l',$ext_p);
                    resize_thumb($photo_n,$photo_n.'_t',$ext_p);

                    $sql_photo = mysql_query("SELECT * FROM `users` WHERE `id` = '".$_SESSION['logged_id']."' LIMIT 1");
                    while($a=mysql_fetch_array($sql_photo)) {

                        if($a['photo']!='') {
                            unlink('../uploads/'.$a['photo'].'_t.jpg');
                            unlink('../uploads/'.$a['photo'].'_l.jpg'); 
                        }

                        unlink('../uploads/'.$photo_n.'.jpg');

                        mysql_query("DELETE FROM `ratings` WHERE `to` = '".$a['id']."'");
                        mysql_query("DELETE FROM `comments` WHERE `to` = '".$a['id']."'");

                    }

                    $height = getimagesize($site_url.'/uploads/'.$photo_n.'_t.jpg');
                    mysql_query("UPDATE users SET `ap` = '".$ap."', `photo` = '".$photo_n."', `size` = '".$height[1]."', `time` = '".time()."' WHERE `id` ='".$_SESSION['logged_id']."' LIMIT 1");

                    echo '
                    <img src="'.show_photo($photo_n,170,170,'l').'" style="border-radius:5px;" /><div style="position:absolute;top:0;right:0;padding:12px;padding-right:7px;padding-top:5px;border-radius:110px; width:12px; border-top-left-radius:0;border-bottom-right-radius:0;background-color:#1e7ca7;color:#fff;font-size:14px;cursor:pointer;border-top-right-radius:10px;border:0px solid #000;" class="delete-img">x</div>';

                } else {
                    echo failed;
                }

            } else {
                echo '<div style="width:166px;height:166px;border:2px solid #ff0000;border-radius:5px;"><div style="margin-top:65px;background-color:#ff0000;color:#fff;padding:10px;">'.max_file_size.'</div></div>';                  
            }

        } else {
            echo '<div style="width:166px;height:166px;border:2px solid #ff0000;border-radius:5px;"><div style="margin-top:65px;background-color:#ff0000;color:#fff;padding:10px;">'.invalid_file_format.'</div></div>';    
        }

    } else {
        echo '<div style="width:166px;height:166px;border:2px solid #ff0000;border-radius:5px;"><div style="margin-top:65px;background-color:#ff0000;color:#fff;padding:10px;">'.select_image.'</div></div>';
    }

}

?>

And message of this error is:

Warning: getimagesize(localhost/uploads/ad88ba4cacfa04317e7b56db59f9815b_t.jpg): failed to open stream: No such file or directory in C:\\wamp\\www\\js\\ajaximage.php on line 122

But this image was uploaded and exist.. what the hell?

122 line:

$height = getimagesize($site_url.'/uploads/'.$photo_n.'_t.jpg');

Please, help.. i don't understand :/

As requested by @usandfriends :)

I assume you've moved files from tmp location, then try a var_dump(getcwd()) to check current working directory, maybe the ../uploads is pointing elsewhere

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