【发布时间】:2014-10-30 01:21:12
【问题描述】:
您好,我有以下代码来创建图像的缩略图然后上传它。当我尝试上传下面附加的图片时,代码失败了,我不知道为什么。在此代码之前,有一个主图像上传,它始终有效,但上面的缩略图脚本大部分时间都有效,但由于某种原因不能附加图像。代码死了,因此页面输出主图像上传成功,但缩略图永远不会上传,页面的其余部分也不会。
此代码还会处理 jpeg 以外的图像吗?如果它不会,我将如何让它处理其他文件类型,如 bmp 和 png?
// load image and get image size
$img = imagecreatefromjpeg( $upload_path . $filename );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_height = $thumbHeight;
$new_width = floor( $width * ( $thumbHeight / $height ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, $upload_paththumbs . $filename );
【问题讨论】:
-
请解释一下“代码失败”是什么意思
-
在此代码之前,有一个主图像上传始终有效,但上面的缩略图脚本大部分时间都有效,但由于某种原因不能附加图像。代码死了,因此页面输出主图像上传成功,但缩略图永远不会上传,页面的其余部分也不会。
-
听起来您没有看到错误。使用
error_reporting = E_ALL和display_errors = On在您的php.ini文件中启用正确的错误报告并重新启动您的网络服务器 -
“php.ini”文件已经按照你说的配置好了
-
您能否检查您的 Web 服务器的错误日志文件中的错误?没有具体错误……那么代码就OK了,可能是参数不对,所以检查所有参数。