duanlianyun0462 2014-09-04 12:02
浏览 53
已采纳

GD2在表单提交后调用函数

The code below executes fine on its own, but when I wrap it with form element statements I get the error "call to undefined function flip in flipit.php line 11, 14 or 17 (depending on the radio button I selected in the form).

This will eventually be incorporated into a file upload page allowing the uploader to flip and/or rotate their image on upload. So it needs to function with a form.

Hope someone can see where I went wrong.

Raw code that executes...

<?php
$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';
$new_img = '../../Uploads/Gallery/copy_bg_200.jpg';

$image = imagecreatefromjpeg($src);
$image = flip($image,1,0); // flips horizontal
//$image = flip($image,0,1); // flips vertical
//$image = flip($image,1,1); // flips both

header("Content-type: image/jpeg");
imagejpeg($image, $new_img, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
$width = imagesx($i);
$height = imagesy($i);
$temp = imagecreatetruecolor($width,$height);
imagecopy($temp,$i,0,0,0,0,$width,$height);
if ($h==1) {
for ($x=0 ; $x<$width ; $x++) {
imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
}
imagecopy($temp,$i,0,0,0,0,$width,$height);
}
if($v==1) {
for ($x=0; $x<$height ; $x++) {
imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
}
}
return $i;
}
header('Location: showme.php'); // page displays the image
?>

Code after form statements added...

<?php
$editFormAction = $_SERVER['PHP_SELF'];

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { // if form is submitted

$src = '../../Uploads/Gallery/drafting_site_bg_200.jpg';
$new_img = '../../Uploads/Gallery/copy_bg_200.jpg';

$image = imagecreatefromjpeg($src);
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Horizontal")) {
$image = flip($image,1,0); // flips horizontal
}
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Vertical")) {
$image = flip($image,0,1); // flips vertical
}
if ((isset($_POST["Flip"])) && ($_POST["Flip"] == "Both")) {
$image = flip($image,1,1); // flips both
}

header("Content-type: image/jpeg");
imagejpeg($image, $new_img, 80);
imagedestroy($image);

function flip($i,$h=1,$v=0) {
$width = imagesx($i);
$height = imagesy($i);
$temp = imagecreatetruecolor($width,$height);
imagecopy($temp,$i,0,0,0,0,$width,$height);
if ($h==1) {
for ($x=0 ; $x<$width ; $x++) {
imagecopy($i, $temp, $width-$x-1, 0, $x, 0, 1, $height);
}
imagecopy($temp,$i,0,0,0,0,$width,$height);
}
if($v==1) {
for ($x=0; $x<$height ; $x++) {
imagecopy($i, $temp, 0, $height-$x-1, 0, $x, $width, 1);
}
}
return $i;
}
header('Location: showme.php'); // page displays the image
}
?>
  • 写回答

1条回答 默认 最新

  • dongqian3750 2014-09-04 14:47
    关注

    Problems seems to be that your function definition is part of your first if code block here – try placing it outside of the conditional block:

    if (…) {
      // …
    }
    
    function flip (…) {
      // …
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口