我的 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;
} }