简体   繁体   English

从POSTED头获取图像文件名(“内容类型:image.jpeg”)

[英]Getting Image Filename from POSTED header('Content-type: image.jpeg')

I'm using Jcrop to allow me to crop an uploaded image to be a users avatar. 我正在使用Jcrop允许我将上传的图片裁剪为用户的头像。

Essentially I'm having trouble with getting the image info from the 'Content-type: image/jpeg' header once the image has been cropped and posted using this form: 本质上,一旦使用以下表单裁剪并发布了图像,我就无法从“ Content-type:image / jpeg”标题中获取图像信息:

<img src='*userimage*' id='cropbox' />
<form action='crop.php' method='post' onsubmit='return checkCoords();'>
<input type='hidden' id='x' name='x' />
<input type='hidden' id='y' name='y' />
<input type='hidden' id='w' name='w' />
<input type='hidden' id='h' name='h' />
<input type='submit' value='Crop Image' />
</form>

The page this posts to only has this code: 此页面发布到的页面只有以下代码:

<?php

$targ_w = $targ_h = 150;
$jpeg_quality = 90;

$src = 'userimages/63/63.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);
?>

This shows the cropped image which is great, but I don't want it posted to the crop.php page like this. 这显示了很好的裁剪图像,但是我不希望这样将其发布到crop.php页面。 I would like to be able to include my site header/footer/style etc and display the cropped image as a filename, so i can then have it approved by the user and saved to their appropriate folder. 我希望能够包含我的网站页眉/页脚/样式等,并将裁剪后的图像显示为文件名,这样我就可以将其批准并保存到相应的文件夹中。

Can anyone help? 有人可以帮忙吗?

Thanks 谢谢

I've figured this out simply by commenting out the Header and specifying the path to save to: 我已经解决了这个问题,只需注释掉Header并指定要保存到的路径:

//header('Content-type: image/jpeg');
imagejpeg($dst_r,"userimages/$user_id/$user_id.jpg",$jpeg_quality);
// Remove from memory
imagedestroy($dst_r);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM