2014-04-01 56 views
0

我想創建裁剪系統php和jquery。我做了一些研究並學習了一些東西。但我目前有問題。在下面的代碼中有確認。我不想遇到這樣的警告。系統的工作原理是這樣的:當你應用這個過程來選擇想要的圖像區域時,會出現以下警告((你想保存圖像..!))但我不想要這樣的警告。你能幫我解決這個問題嗎? http://goo.gl/zXhvGG作物確認jquery

function getSizes(im, obj) { 
    var x_axis = obj.x1; 
    var x2_axis = obj.x2; 
    var y_axis = obj.y1; 
    var y2_axis = obj.y2; 
    var thumb_width = obj.width; 
    var thumb_height = obj.height; 
    if (thumb_width > 0) { 
     if (confirm("Do you want to save image..!")) { 
      $.ajax({ 
       type: "GET", 
       url: "ajax_image.php?t=ajax&img=" + $("#image_name").val() + "&w=" + 
        thumb_width + "&h=" + thumb_height + "&x1=" + x_axis + "&y1=" + y_axis, 
       cache: false, 
       success: function (rsponse) { 
        $("#cropimage").hide(); 
        $("#thumbs").html(""); 
        $("#thumbs").html("<img src='uploads/" + rsponse + "' />"); 
       } 
      }); 
     } 
    } else 
     alert("Please select portion..!"); 
} 
$(document).ready(function() { 
    $('img#photo').imgAreaSelect({ 
     aspectRatio: '1:1', 
     onSelectEnd: getSizes 
    }); 
}); 

PHP

<?php 

    $valid_formats = array("jpg", "png", "gif", "bmp"); 
    if(isset($_POST['submit'])) 
     { 
      $name = $_FILES['photoimg']['name']; 
      $size = $_FILES['photoimg']['size']; 

      if(strlen($name)) 
       { 
        list($txt, $ext) = explode(".", $name); 
        if(in_array($ext,$valid_formats) && $size<(1024*1024)) 
         { 
          $actual_image_name = time().substr($txt, 5).".".$ext; 
          $tmp = $_FILES['photoimg']['tmp_name']; 
          if(move_uploaded_file($tmp, $path.$actual_image_name)) 
           { 
           mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'"); 
            $image="<h1>Please drag on the image</h1><img src='uploads/".$actual_image_name."' id=\"photo\" style='max-width:500px' >"; 

           } 
          else 
           echo "failed"; 
         } 
        else 
         echo "Invalid file formats..!";     
       } 
      else 
       echo "Please select image..!"; 
     } 
?> 

HTML

<div style="margin:0 auto; width:600px"> 
<?php echo $image; ?> 
<div id="thumbs" style="padding:5px; width:600px"></div> 
<div style="width:600px"> 

<form id="cropimage" method="post" enctype="multipart/form-data"> 
    Upload your image <input type="file" name="photoimg" id="photoimg" /> 
    <input type="hidden" name="image_name" id="image_name" value="<?php echo($actual_image_name)?>" /> 
    <input type="submit" name="submit" value="Submit" /> 
</form> 

</div> 
</div> 

Ajax.php

<?php 
include('db.php'); 
session_start(); 
$session_id='1'; // Session_id 
$t_width = 100; // Maximum thumbnail width 
$t_height = 100; // Maximum thumbnail height 
$new_name = "small".$session_id.".jpg"; // Thumbnail image name 
$path = "uploads/"; 
if(isset($_GET['t']) and $_GET['t'] == "ajax") 
    { 
     extract($_GET); 
     $ratio = ($t_width/$w); 
     $nw = ceil($w * $ratio); 
     $nh = ceil($h * $ratio); 
     $nimg = imagecreatetruecolor($nw,$nh); 
     $im_src = imagecreatefromjpeg($path.$img); 
     imagecopyresampled($nimg,$im_src,0,0,$x1,$y1,$nw,$nh,$w,$h); 
     imagejpeg($nimg,$path.$new_name,90); 
     mysql_query("UPDATE users SET profile_image_small='$new_name' WHERE uid='$session_id'"); 
     echo $new_name."?".time(); 
     exit; 
    } 

    ?> 
+0

爲什麼不乾脆換出'確認(..)'和'1'或者'真',所以你不必擔心修改'if'阻止? –

+0

你爲什麼不刪除確認條件? – uchamp

+0

@uchamp謝謝你的回覆你可以檢查我的問題在這個鏈接http://goo.gl/zXhvGG – somebodyknowsme

回答

0

您需要從您的js代碼中刪除確認。所以,使用此代碼,而不是

<script type="text/javascript"> 
    function getSizes(im, obj) { 
     var x_axis = obj.x1; 
     var x2_axis = obj.x2; 
     var y_axis = obj.y1; 
     var y2_axis = obj.y2; 
     var thumb_width = obj.width; 
     var thumb_height = obj.height; 
     if (thumb_width > 0) { 
      $.ajax({ 
       type: "GET", 
       url: "ajax_image.php?t=ajax&img=" + $("#image_name").val() + "&w=" + thumb_width + "&h=" + thumb_height + "&x1=" + x_axis + "&y1=" + y_axis, 
       cache: false, 
       success: function (rsponse) { 
        $("#cropimage").hide(); 
        $("#thumbs").html(""); 
        $("#thumbs").html("<img src='uploads/" + rsponse + "' />"); 
       } 
      }); 
     } 
    } 
    $(document).ready(function() { 
     $('img#photo').imgAreaSelect({ 
      aspectRatio: '1:1', 
      onSelectEnd: getSizes 
     }); 
    }); 
     </script> 
+0

這段代碼是對的謝謝你。但是,如何在Crop中添加Save按鈕你能幫助我嗎? – somebodyknowsme

+0

你能幫我嗎? – somebodyknowsme