我正在使用表单上传图像。图片上传后,我们将能够看到上传的图片。然后我使用JCrop
( http://deepliquid.com/content/Jcrop.html ) 允许裁剪此图像。假设我只关心JPEG
图像。然后我准备提交表格。
提交表单后,我将执行一些图像处理并裁剪图像。但是我想把这个裁剪图像的信息放回$_FILES
数组中(这是必须的)。我将如何$_FILES
在 PHP 脚本中操作这个数组?
这是我尝试过的,但它不起作用。
$upload_dir = '/Users/user/Sites/tmp/';
$file_name = $_FILES['image']['name'];
$file_name = "cropped_".$file_name;
$tmp_name = $_FILES['image']['tmp_name'];
$file_size = $_FILES['image']['size'];
$src_file = imagecreatefromjpeg($tmp_name);
list($width,$height) = getimagesize($tmp_name);
// Creates cropped image
$tmp = imagecreatetruecolor($_POST['w'], $_POST['h']);
imagecopyresampled($tmp, $src_file, 0, 0, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $_POST['w'], $_POST['h']);
$small_pic_file_path = $upload_dir.$file_name;
imagejpeg($tmp,$small_pic_file_path,85);
$message = "<img src='http://localhost/~user/tmp/".$file_name."'>";
$_FILES['image']['name'] = $file_name;
$_FILES['image']['type'] = "image/jpeg";
// unlink($tmp_name);
// if(!move_uploaded_file($upload_dir.$file_name, $tmp_name)) echo "Failure Moving Image";
$_FILES['image']['tmp_name'] = $upload_dir.$file_name;
$_FILES['image']['error'] = 0;
$sizes = getimagesize($upload_dir.$file_name);
$_FILES['image']['size'] = ($sizes['0'] * $sizes['1']);
可以改变这个$_FILES
数组吗?