CloudFlare运行时PHP代码无法正常工作?

时间:2018-08-01 21:33:27

标签: php jquery cloudflare jcrop

下面的代码过去可以完美地裁剪已经上传(通过JQuery JCrop)的图像。一旦我配置了CloudFlare,它就无法裁剪图像(但仍成功上传)。有关如何解决此问题的任何想法?

我当前的PHP版本是7.0,并且我将DigitalOcean用作网络主机。

<?php

require_once('auth.php');
require_once('connection.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
 $targ_w = 150;
 $targ_h = 200;


 $src = mysqli_real_escape_string($bd,$_POST['src']);

 $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

 $img = resize_image($src, $_POST['imgWidth'], $_POST['imgHeight']);

 imagecopyresampled($dst_r,$img,0,0,$_POST['x'],$_POST['y'],150,200,$_POST['w'],$_POST['h']);

 imagejpeg($dst_r,$src,90);


 //Cropping complete, move to next page

 //header("location: profileSetup.php");



 exit; 
 }


function isPNG($file){
    return preg_match('/'.quotemeta('PNG').'/i', file_get_contents($file));
}



function resize_image($file, $w, $h, $crop=FALSE) {
    list($width, $height) = getimagesize($file);
    $r = $width / $height;
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width-($width*abs($r-$w/$h)));
        } else {
            $height = ceil($height-($height*abs($r-$w/$h)));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w/$h > $r) {
            $newwidth = $h*$r;
            $newheight = $h;
        } else {
            $newheight = $w/$r;
            $newwidth = $w;
        }
    }



    $dst = imagecreatetruecolor($newwidth, $newheight);

    if(exif_imagetype($file) != IMAGETYPE_JPEG){
        $src = imagecreatefrompng($file);
    }
    else{
        $src = imagecreatefromjpeg($file);
    }



    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    return $dst;
}


?>

1 个答案:

答案 0 :(得分:0)

我终于为自己解决了这个问题。 PHP代码没有错。 CloudFlare正在缓存图像,我要做的就是在新的图像名称中添加一个随机整数以防止这种情况发生!