如何解决Ajax Forbidden 403 - GD

时间:2015-12-14 20:45:53

标签: php jquery ajax .htaccess

我有以下代码:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#ajax_form').submit(function(){
var dados = jQuery( this ).serialize();


jQuery.ajax({
type: "POST",
url: "processa.php",
data: dados,
success: function( data )
{
$('#imagem').attr("src",data);
}
});


return false;
});
});
</script>
</head>
<body> 


// FORM 


<form method="post" action="" id="ajax_form"> 
   Title <input type = "text" name="titulo" value="">
    X <input type = "text" name="x" value="">
    Y <input type = "text" name="y" value=""> 
      <input type="submit" name="enviar" value="Enviar" />
</form>


// Here I am trying to print the updated image
<img id="imagem" src="<?php $texto?>.jpg">
</body>


</html>

file processa.php

  <?php


if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 $titulo = $_POST['titulo'];
 $x = $_POST['x'];
 $y = $_POST['y'];


}


// Generate image using the GD library
$texto = $titulo; // content from post form
$font_size = 10; 
$font_file = 'arial.ttf'; 
$texto = wordwrap($texto, 11, "\n", true);
 $x = $x; // has the form
 $y = $y; // has the form
 $imagem = imagecreate(50, 50); 
$fundo= imagecolorallocate($imagem , 0, 0, 0); 
$letra= imagecolorallocate($imagem , 255, 255, 255); 


imagettftext($imagem, $font_size, 0, $x, $y, $letra, $font_file, $texto);
 imagejpeg($imagem, $texto.".jpg", 100); // saved image directory 
imagedestroy($imagem); 
echo $texto.".jpg";
?>

在processa.php文件中,应该创建一个图像,其中包含标题和表单中报告的填充X和Y值。

文件名是相同的标题。

在谷歌Chrome控制台中,点击提交大约需要30秒,并且显示为禁止403,图像在源代码中出现的位置会更改为相同的控制台错误,但总结如下:

<img id="imagem" src="<br /> <font size='1'<table class='xdebug-error xe-warning' dir='ltr' bor...eeec'>..\processa.php<b>:</b>76</td></tr>
</table></font>
test.jpg">
test.jpg就是在titulo领域所说的。但是不生成GD图像。

我尝试解决输入.htaccess

时禁止的错误
 RewriteRule ^site\/?$ /site/form.php [NC,L]  
 RewriteRule ^site\/?$ /site/processa.php [NC,L]   // entering this

但到目前为止还没有得到解决方案

谢谢帮助

修改

将完整路径放在ajax中,即使是在同一个文件夹中。这解决了这个问题。感谢用户@Dagon

0 个答案:

没有答案