if ( $_FILES["ufile"]["type"] [$i] == "image/jpeg" || $_FILES["ufile"]["type"] [$i] == "image/jpg" || $_FILES["ufile"]["type"] [$i] == "image/png" || $_FILES["ufile"]["type"] [$i] == "image/gif" )
{
if ($_FILES["ufile"]["type"] [$i] == "image/png" || $_FILES["ufile"]["type"] [$i] == "image/gif" || $_FILES["ufile"]["type"] [$i] == "image/jpeg" || $_FILES["ufile"]["type"] [$i] == "image/jpg" )
{
$file=$_FILES["ufile"]["tmp_name"];
list($width, $height) = getimagesize($file);
$new_width = 200;
$new_height = 500;
$dst_image = imagecreatetruecolor($new_width,$new_height);
$src_image = imagecreatefromjpeg($_FILES["ufile"]["tmp_name"]);
imagecopyresized ($dst_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg(imagecreatefromstring(file_get_contents($dst_image)), "convert.jpg");
$actual_image_name = $name[$i].'.'.'jpg';
move_uploaded_file("convert.jpg", $path.$actual_image_name);
}
}
图片已上传但尺寸仍与来源相同
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- duanchun1852 2015-01-06 16:15关注
You are totally mis-using GD.
$dst_image
is a GD image handle. It is not a file. So...file_get_contents()
will return boolean FALSE, since you're trying to fetch from something that is not a filename.imagecreatefromstring()
will return boolean false, since a boolean false is not an image string, andimagejpeg()
will return boolean FALSE since you're not passing it a GD Handle.In short, your code could do with some improvement. You simply assume nothing could ever go wrong, don't ever check for failure, and those failures propagate onwards through the code.
All you really needed was
image_jpeg($dst_image, 'convert.jpg');
And then your
move_uploaded_file
will also fail, since "convert.jpg" isn't an uploaded file. It's a file you've created yourself on the server. It may have been based on an uploaded file, but in and of itself is not an uploaded file. Why not justimage_jpeg($dst_image, "$path/$actual_image_name");
解决 无用评论 打赏 举报
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效