getimagesize()错误:“无法打开流:没有这样的文件或目录”

时间:2013-11-29 02:11:26

标签: php jquery html image

我有这个问题,我不知道我该怎么办?

这是我的剧本:

<?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>';
    }

}

&GT;

此错误的消息是:

警告:getimagesize(localhost / uploads / ad88ba4cacfa04317e7b56db59f9815b_t.jpg):无法打开流:第122行的C:\ wamp \ www \ js \ ajaximage.php中没有此类文件或目录

但是这张图片已上传并存在......到底是怎么回事?

122行:

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

请帮助..我不明白:/

1 个答案:

答案 0 :(得分:1)

根据@usandfriends的要求:)

我假设您已从tmp位置移动文件,然后尝试var_dump(getcwd())检查当前工作目录,可能../uploads指向其他地方