0

ページが作成されると呼び出される私のphpページにpostメソッドがあります。この同じページにフォームがあり、クリックすると、トリミングされた画像でページが「更新」されます。これを実行すると、画面に奇妙なテキストが表示されます。

最初の投稿方法:

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

if($_FILES['afbeelding']['error'] == 0) {
    $imageinfo = getimagesize($_FILES['afbeelding']['tmp_name']);
    if(filesize($_FILES['afbeelding']['tmp_name']) > 204800) {?> <script type="text/javascript"> alert("Maximale bestandsgrootte: 200KB"); window.location = "/inside.php"</script> <?php }
    else{
    move_uploaded_file($_FILES['afbeelding']['tmp_name'], 'images/' . $_FILES['afbeelding']['name']);}

フォーム:

<form method="post" action="?action=showCrop">
        <input type="hidden" name="x" value="" />
        <input type="hidden" name="y" value="" />
        <input type="hidden" name="w" value="" />
        <input type="hidden" name="h" value="" />
        <input type="hidden" name="image" value="images/<?php echo $_FILES['afbeelding']['name']; ?>" />
        <input type="submit" value="Verklein afbeelding!" name="submit"/>
    </form>
    <?php
    echo '<img src="getimage.php?file=images/' . $_FILES['afbeelding']['name'] . '">';

フォームを送信した後に呼び出されるメソッドは次のとおりです。

function showCrop(){
$targ_w = $_POST['w'];
$targ_h = $_POST['h'];
$jpeg_quality = 90;

$src = $_POST['image'];
$ext = end(explode(".", $_POST['image']));
switch($ext)
{
  case 'jpg';
  $img_r = imagecreatefromjpeg($src);
  $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

  imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
  $targ_w,$targ_h,$_POST['w'],$_POST['h']);

  //header('Content-type: image/jpeg');
  imagejpeg($dst_r,null,$jpeg_quality);
  exit;
  break;
  case 'png';
  $img_r = imagecreatefrompng($src);
  $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

  imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
  $targ_w,$targ_h,$_POST['w'],$_POST['h']);

  //header('Content-type: image/png');
  imagepng($dst_r,null,8);
  exit;
  break;              

} }

4

0 に答える 0