Warning: imagecreatefromjpeg(7.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in D:\wwwroot\love\cs1.php on line 41Warning: imagesx(): supplied argument is not a valid Image resource in D:\wwwroot\love\cs1.php on line 46Warning: imagesy(): supplied argument is not a valid Image resource in D:\wwwroot\love\cs1.php on line 47Warning: Division by zero in D:\wwwroot\love\cs1.php on line 51Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\wwwroot\love\cs1.php on line 91Warning: imagecopyresampled(): supplied argument is not a valid Image resource in D:\wwwroot\love\cs1.php on line 92Warning: imagejpeg(): supplied argument is not a valid Image resource in D:\wwwroot\love\cs1.php on line 94

解决方案 »

  1.   

    $source_img=$_FILES['image']['name'];   =>  $source_img = $_FILES['image']['tmp_name']
      

  2.   

    楼上的说得对!再有就是这个$target_dir='./2222';,如果你这个真的是目录的话,应该是$target_dir='./2222/';这样的,这个也算是一个错误。你使用了缩略图的代码,但是你没有生命一个类,关于缩略图的类,所以你的很多关于缩略图的函数都是报错:supplied argument is not a valid请添加如下代码:$img=new HanroadClass;然后使用有关缩略图的函数的时候请使用如下形势:
    $img->imagejpeg($new_img,$tar_url);
      

  3.   


    这样没问题:但怎么通过表单传图片<?PHP 
     
    $source_img = "IT服装2.png";
    echo $source_img;
    $target_dir='./2222/';
    $new_width=112;
    $new_height=137;
    $if_cut=0;
    $target_name='1';
    $img=new HanroadClass;
      $img->HrResize($source_img,$target_dir,$target_name,$new_width,$new_height,$if_cut); 
     class HanroadClass 

        /**//********************** 
        利用PHP的GD库生成缩略图。 
        支持图片格式:jpg,gif,png 
     
        $source_img:  源图象完整路径 
        $target_dir:  目标图象目录 
        $target_name: 目标图象名称 
        $new_width:   目标图象宽 
        $new_height:  目标图象高 
        $if_cut:      是否裁图 
            1(裁图): 裁图则按设置的大小生成目标图象 
            0(不裁): 不裁则按比例生成目标图象 
        **********************/ 
        function HrResize($source_img,$target_dir,$target_name,$new_width,$new_height,$if_cut) 
        { 
            //图片类型 
            $img_type = strtolower(substr(strrchr($source_img,"."),1)); 
     
            //图象的完整目标路径 
            $tar_url = $target_dir."/".$target_name.".".$img_type; 
     
            //初始化图象 
            if($img_type=="jpg") $temp_img = imagecreatefromjpeg($source_img); 
            if($img_type=="gif") $temp_img = imagecreatefromgif($source_img); 
            if($img_type=="png") $temp_img = imagecreatefrompng($source_img); 
     
            //原始图象的宽和高 
            $old_width  = imagesx($temp_img); 
            $old_height = imagesy($temp_img); 
     
            //改变前后的图象的比例 
            $new_ratio = $new_width/$new_height; 
            $old_ratio = $old_width/$old_height; 
     
            //生成新图象的参数 
            //情况一:裁图 则按设置的大小生成目标图象 
            if($if_cut=="1") 
            { 
                $new_width  = $new_width; 
                $new_height = $new_height; 
                //高度优先 
                if($old_ratio>=$new_ratio) 
                { 
                    $old_width  = $old_height*$new_ratio; 
                    $old_height = $old_height; 
                } 
                //宽度优先 
                else 
                { 
                    $old_width  = $old_width; 
                    $old_height = $old_width/$new_ratio; 
                } 
            } 
            //情况二:不裁图 则按比例生成目标图象 
            else 
            { 
                $old_width  = $old_width; 
                $old_height = $old_height; 
                //高度优先 
                if($old_ratio>=$new_ratio) 
                { 
                    $new_width  = $new_width; 
                    $new_height = $new_width/$old_ratio; 
                } 
                //宽度优先 
                else 
                { 
                    $new_width  = $new_height*$old_ratio; 
                    $new_height = $new_height; 
                } 
            } 
            //生成新图片 
            $new_img = imagecreatetruecolor($new_width,$new_height); 
            imagecopyresampled($new_img,$temp_img,0,0,0,0,$new_width,$new_height,$old_width,$old_height); 
     
            if($img_type=="jpg") imagejpeg($new_img,$tar_url); 
            if($img_type=="gif") imagegif($new_img,$tar_url); 
            if($img_type=="png") imagepng($new_img,$tar_url); 
        } 

    ?> 
    <table width="112" height="137" border="0" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#CCCCCC">
      <tr>
        <td bgcolor="#FCFCFC"><div align="center"><img src="<? echo("./图片/".$source_img.".jpg?reload=".rand(0,999999)); ?>" /></div></td>
      </tr>
    </table>
    <br><br> 
    <form enctype="multipart/form-data" method="post"> 
    <br> 
    <input type="file" name="image" size="50" value="浏览"><p> 
    <input type="submit" value="上传图片"> 
    </form>  
    </body> 
    </html>
      

  4.   

    怎么把表单form enctype="multipart/form-data" method="post"> 
    <br> 
    <input type="file" name="image" size="50" value="浏览"><p> 
    <input type="submit" value="上传图片"> 
    </form>  传给变量 $source_img $source_img = "IT服装2.png";这段代码应该怎么写??
      

  5.   

    $upload_postfile=$_FILES["image"];
    if(is_array($upload_postfile)){
    $up_file=$upload_postfile["tmp_name"];
    $up_file_name=$upload_postfile["name"];
    $up_file_type=$upload_postfile["type"];
    $up_file_size=$upload_postfile["size"];
    }else{
    $up_file=$upload_postfile;
    $up_file_name=$upload_postfile_name;
    $up_file_type=$upload_postfile_type;
    $up_file_size=$upload_postfile_size;
    }