2017-03-17 4 views
1

以下のコードを使用して、サーバーに保存されているイメージを回転して保存します。Ajaxコールに変数を渡す

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://beneposto.pl/jqueryrotate/js/jQueryRotateCompressed.js"></script> 

<img src="uploads/101822973264163759893-1428320267361.jpeg" id="img"/> 

<script> 
$(document).ready(function(){ 
var value = 0 
    $("#img").rotate({ 
     bind: 
     { 
      click: function(){ 
       value +=90; 
       $(this).rotate({ animateTo:value}) 
      } 
     } 

    }); 


    $(document).on('click', '#img', function() { 
       // alert("Hello"); 

       var idno = "test"; 
       $.ajax({ 
         url: "saveimage.php", 
         dataType: "html", 
         type: 'POST', 
         data: "panelid="+idno, //variable with data 
         success: function(data){ 
          // $(".test").html(data); 
           // alert(data); 
         } 
       }); 
    }); 
}); 
</script> 

saveimage.php

<?Php 
$degrees = -90; //change this to be whatever degree of rotation you want 

header('Content-type: image/jpeg'); 

$filename = 'uploads/101822973264163759893-1428320267361.jpeg'; //this is the original file 

$source = imagecreatefromjpeg($filename) or notfound(); 
$rotate = imagerotate($source,$degrees,0); 

imagejpeg($rotate,$filename); //save the new image 

imagedestroy($source); //free up the memory 
imagedestroy($rotate); //free up the memory 

?> 

は、私はここで、このコードを発見した - http://www.codehaven.co.uk/rotate-and-save-an-image-using-php/

これはすべて正常に動作しますが、画像パスと名前をajax呼び出しに保持するPHP変数を渡そうとしていますが、これを行う方法はわかりません。

誰でも手助けできますか?

おかげで、

ジョン

答えて

1

あなたがURLパラメータとして変数を渡すことができます。

url: "saveimage.php?path=/folder/to/your/image/&image=image_name", 

あなたはすべての特殊文字が

+0

感謝を通過していることを確認するでurlencodeを使用することができます!それは私が思ったよりも簡単でした。 –

関連する問題