Estoy usando el siguiente código para rotar y guardar una imagen almacenada en el servidor.
<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>guardarimagen.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 ?>Encontré este código aquí: http://www.codehaven.co.uk/rotate-and-save-an-image-using-php/ .
Todo esto funciona bien, pero estoy tratando de pasar una variable de PHP que contiene la ruta de la imagen y el nombre de la llamada ajax y no tengo idea de cómo hacerlo.
¿Alguien puede ayudar?
Gracias,
John
Puede pasar la variable como parámetros de URL:
url: "saveimage.php?path=/folder/to/your/image/&image=image_name",Puede usar urlencode para asegurarse de que todos los caracteres especiales se transfieran