2017-03-17 1 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/.

이 모든 것은 잘 작동하지만 이미지 경로와 이름을 아약스 호출에 저장하고이를 수행하는 방법에 대해서는 알지 못하는 PHP 변수를 전달하려고합니다.

아무도 도와 줄 수 있습니까?

덕분에,

당신은 URL 매개 변수로 변수를 전달할 수 있습니다

답변

1

:

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

당신은 확인하기를 urlencode를 사용할 수있는 모든 특수 문자가

+0

감사를 통과하고 있습니다! 그것은 내가 생각했던 것보다 쉬웠다. –

관련 문제