dongnan4571 2014-01-07 05:26
浏览 41

裁剪后图像不保存到目录中

I am trying to save cropped image after cropping into a directory but when i click on crop button nothing happens. I am stuck in it from 2 days please someone help me out. I am getting these errors

Warning: imagecreatefromjpeg(public/image/) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\wamp\www\ModuleEx.com\application\modules\admin\controllers\IndexController.php on line 64

Warning: imagecreatefromjpeg(public/image/) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in C:\wamp\www\ModuleEx.com\application\modules\admin\controllers\IndexController.php on line 64

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'public/image/crop' for writing: Permission denied in C:\wamp\www\ModuleEx.com\application\modules\admin\controllers\IndexController.php on line 71

Here is my controller code

if(isset($_FILES['file']['name'])){ //user upload file
    $file_name = stripslashes($_FILES['file']['name']);
    $ext_idx = strrpos($file_name,".");
    if(!$ext_idx) //hide this if ur app can upload without ext
        echo "File invalid.";
    else{
        $ext_length = strlen($file_name) - $ext_idx;
        $extension = strtolower(substr($file_name,$ext_idx+1,$ext_length));
        //allowed extension
        $ext_list = array("pdf", "doc","jpg", "jpeg", "gif", "png");
        if(!in_array($extension, $ext_list))
            echo "System can't support your extension.";
        else{
            $size = (2500 * 1024); //2500 Kb
            $file_size=filesize($_FILES['file']['tmp_name']);
            if($file_size > $size)
                echo "File is oversize. Max 2500 Kb.";
            else{
                //change name
                $file_name = rand(10,1000).".".$extension;

                $file_obj="public/image/".$file_name;



                $copied = copy($_FILES['file']['tmp_name'], $file_obj);

                if(!$copied)
                    echo "Failed.";
                else 
                {

                    $file_data = array( 'file_name' => $file_name );


                    $this->view->file_obj=$file_obj;




                }
                }

            }
        }
    }

Here is my phtml code.

if ($_SERVER['REQUEST_METHOD'] == 'POST')
 {
$targ_w = $targ_h = 150;
$jpeg_quality = 90;

 $src = 'file_obj';
$img_r = imagecreatefromjpeg($src);
 $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

 imagecopyresampled($dst_r,$img_r,0,0,(int)$_POST['x'],(int)$_POST['y'],
 $targ_w,$targ_h,(int)$_POST['w'],(int)$_POST['h']);

 //header('Content-type: image/jpeg');
  imagejpeg($dst_r,'file_obj',$jpeg_quality);

   }


    ?>




 <html>
  <head>

   <script src="public/js/jquery.min.js"></script>
  <script src="public/js/jquery.Jcrop.js"></script>
   <script src="public/js/jquery.color.js"></script>
  <script type="text/javascript">


  $(function(){

  $('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords
 });

   });

   function updateCoords(c)
   {
  $('#x').val(c.x);
 $('#y').val(c.y);
 $('#w').val(c.w);
 $('#h').val(c.h);
 };

 function checkCoords()
  {
 if (parseInt($('#w').val())) return true;
 alert('Please select a crop region then press submit.');
 return false;
 };

  </script>


  <style type="text/css">
  #target {
   background-color: #ccc;
   width: 500px;
     height: 330px;
    font-size: 24px;
    display: block;
  }


  </style>


 <?=$this->headLink()->appendStylesheet('/public/css/demos.css');?>
 <?=$this->headLink()->appendStylesheet('/public/css/main.css');?>
 <?=$this->headLink()->appendStylesheet('/public/css/jquery.Jcrop.min.css');?>
</head>

<body>
   <form id="file_form" method="POST" enctype="multipart/form-data" action="" onsubmit="">
    <input type="file" name="file" />

     <input type="submit" name="submit"  value="Upload"/><br/></br>
     <img id="cropbox" src="<?php echo $this->file_obj?>" alt="Image" style="display: block; visibility: visible; width: 602px; height: 400px; border: medium none; opacity: 0.5;"/><br/>

        <input type="hidden" id="x" name="x" />
        <input type="hidden" id="y" name="y" />
        <input type="hidden" id="w" name="w" />
        <input type="hidden" id="h" name="h" />
        <input type="submit" value="Crop Image" class="btn btn-large btn-inverse" />
  </form>


</body>
</html>
  • 写回答

2条回答 默认 最新

  • drd2551 2014-01-07 09:30
    关注

    Maybe this helps. * Where specifically does your folder(public/image) or it's path stored? Does it also lies with the same directory with your IndexController.php?

    This is my code in saving an image in a folder: $path = "uploads/";

    $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
    $tmp = $_FILES['photoimg']['tmp_name'];
    if(move_uploaded_file($tmp, $path.$actual_image_name))
    {
        mysql_query("UPDATE lms_users SET userPic='$actual_image_name' WHERE userId='$_SESSION[email]'");                       
        echo "<img src='uploads/".$actual_image_name."'  class='preview'>";
    }
    else
    echo "failed";
    

    Hopes this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线