JQuery Ajax数据发送时间为500内部服务器错误

时间:2014-03-01 08:17:08

标签: php jquery ajax

的index.php

<?php
$path = "uploads/";
$image = "";
?>
<html>
<head>
<title></title>
</head>
<link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script>
<script type="text/javascript">
function getCropImage(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;

    $.ajax({
        type:"GET",
        url:"flipimage.php?t=ajax&img="+$("#image_name").val()+"&w="+thumb_width+"&h="+thumb_height+"&x1="+x_axis+"&y1="+y_axis,
        cache:false,
        success:function(response)
        { 
            //$("#cropimage").hide();
            $("#thumbs").html("");
            $("#thumbs").html("<img src='uploads/"+response+"' width='700px' height='400px'/>");
        }
    });
}

$(document).ready(function () {
    $('img#photo').imgAreaSelect({
        maxWidth: 1,
//      maxHeight: 1,
        onSelectEnd: getCropImage
    });
});
</script>
<?php

    $valid_formats = array("jpg", "jpeg", "png", "gif", "bmp","JPG", "PNG", "GIF", "BMP", "JPEG");
    $maxImgSize = 5*1024*1024;
    $randomName = md5(uniqid().date("Y-m-d H:i:s"));
    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 < $maxImgSize)
                {
                    $randomImageName = $randomName.".".$ext;
                    $tmp = $_FILES['photoimg']['tmp_name'];
                    if(move_uploaded_file($tmp, $path.$randomImageName))
                    {
                        $image="<div>Please select the portion</div><img src='uploads/".$randomImageName."' id=\"photo\" >";
                    }
                    else {
                        if ($_FILES["photoimg"]["error"] > 0)
                        {
                            echo "Error: " . $_FILES["photoimg"]["error"] . "<br>";
                        }
                    }
                }
                else
                {
                    if($_FILES["photoimg"]["size"] > $maxImgSize)
                        echo "Maximum file size exceeded";
                    else
                        echo "Invalid file";
                 }
            }
            else
                echo "Please select a image";
        }
?>
<body>
    <div>
        <div>
            <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($randomImageName)?>" />
                <input type="submit" name="submit" value="Submit" />
            </form>
        </div>
        <div>
            <div>
                <?php if($image != ''){ echo $image; }?>
            </div>
            <div id="thumbs" style="margin-top:40px;"></div>
        <div>
    </div>
</body>
</html>

flipimage.php

<?php
$path = "uploads/";

function flip($image,$h=1,$v=0,$wid) 
{
    $width = imagesx($image);
    $height = imagesy($image);
    $temp = imagecreatetruecolor($width,$height);
    imagecopy($temp,$image,0,0,0,0,$width,$height);

    $image1 = imagecreatetruecolor($width,$height);
    imagecopy($image1,$image,0,0,0,0,$width,$height);

    $leftwidth = 2*$wid;
    $totWid = (2*$width);
    $finalImage = imagecreatetruecolor($totWid,$height);

    if ($h==1) {
        for ($x=0 ; $x<$width ; $x++) 
        {
            imagecopy($image1, $temp, $width-($x)-1, 0, $x, 0, 1, $height);
        }
    }

    for ($x=0 ; $x<=$wid ; $x++) 
    {
        imagecopy($finalImage, $image, $x, 0, $x, 0, 1, $height);
        imagecopy($finalImage, $image1, $leftwidth-($x), 0, $width-($x), 0, 1, $height);
    }

    $rightWidth = $totWid-$leftwidth;
    for ($x=0; $x<=$width-$wid; $x++) 
    {
        imagecopy($finalImage, $image, $totWid-$x, 0, $width-$x, 0, 1, $height);
        imagecopy($finalImage, $image1, $leftwidth+$x, 0, $x, 0, 1, $height);
    }

    return $finalImage;
}
if(isset($_GET['t']) and $_GET['t'] == "ajax")
{
    extract($_GET);

    $extension = strtolower(strrchr($img, '.'));
    $file = $path.$img;
    switch ($extension) {
        case '.jpg':
            $image = imagecreatefromjpeg($file);
            break;
        case '.gif':
            $image = imagecreatefromgif($file);
            break;
        case '.png':
            $image = imagecreatefrompng($file);
            break;
        default:
            $image = false;
            break;
    }

    $new_name = "flip".$img;
    $image = flip($image,1,0,$x1);
    header("Content-type: image/jpeg");
    imagejpeg($image,$path.$new_name,90);
    echo $new_name.'?'.time();
    exit;
}
?>

我正在尝试执行此AJAX帖子但由于某种原因我收到服务器500错误。所以问题似乎在于通话时间。但它在localhost中工作正常。但是发生了实时错误。

0 个答案:

没有答案