doulun1915 2014-03-01 08:17
浏览 36

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

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;
}
?>

I am trying to perform this AJAX post but for some reason I am getting a server 500 error. So the problem seems to be on the calltime. but it's working fine in localhost. but in live error occur.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度