有谁能告诉我,如何解决以下问题?
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /var/www/html/_controls/_images.php on line 28
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/var/tmp/phpaFbMJV' is not a valid JPEG file in /var/www/html/_controls/_images.php on line 28
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/html/_controls/_images.php on line 52
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /var/www/html/_controls/_images.php on line 28
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/var/tmp/phpaFbMJV' is not a valid JPEG file in /var/www/html/_controls/_images.php on line 28
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/html/_controls/_images.php on line 52
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /var/www/html/_controls/_images.php on line 28
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/var/tmp/phpUakeQQ' is not a valid JPEG file in /var/www/html/_controls/_images.php on line 28
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/html/_controls/_images.php on line 52
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/_controls/_images.php:28) in /var/www/html/_templates/code/admin/edit_project_image.php on line 40
我的源代码:
<?
class image_control
{
public $raw_image = "";
public $temp_loc = "";
public $image = "";
public $image_resized = "";
public $name = "";
public $type = "";
public $width = "";
public $height = "";
public $resize_to_width = "";
public $resize_to_height = "";
public $errors = array();
function __construct($raw_file_post){
$this->raw_image = $raw_file_post;
$this->temp_loc = $raw_file_post['tmp_name'];
$this->name = $raw_file_post['name'];
if($raw_file_post['type'] == "image/jpeg" || $raw_file_post['type'] == "image/pjpeg"){
$this->type = 'jpeg';
$this->image = imagecreatefromjpeg($this->temp_loc);
}
elseif($raw_file_post['type'] == "image/png" || $raw_file_post['type'] == "image/x-png"){
$this->type = 'png';
$this->image = imagecreatefrompng($this->temp_loc);
}
elseif($raw_file_post['type'] == "image/gif"){
$this->type = 'gif';
$this->image = imagecreatefromgif($this->temp_loc);
}
else
$error[] = 001;
list($this->width, $this->height) = getimagesize($this->temp_loc);
$this->image_resized = imagecreatetruecolor($this->width, $this->height);
imageantialias($this->image_resized, true);
imagealphablending($this->image_resized, false);
imagesavealpha($this->image_resized,true);
$transparent = imagecolorallocatealpha($this->image_resized, 255, 255, 255, 127);
imagefilledrectangle($this->image_resized, 0, 0, $this->width, $this->height, $transparent);
imagecopyresampled($this->image_resized, $this->image, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);
$this->image = $this->image_resized;
$this->image_resized = "";
}
function resize($width, $height, $resample = false){
if($width !== '' && $width !== NULL && $width !== 'auto')
$this->resize_to_width = $width;
if($height !== '' && $height !== NULL && $height !== 'auto')
$this->resize_to_height = $height;
if($width == 'auto' || $height == 'auto'){
if($height == 'auto')
$this->resize_to_height = ($this->resize_to_width / $this->width) * $this->height;
if($width == 'auto')
$this->resize_to_width = ($this->resize_to_height / $this->height) * $this->width;
}
$this->image_resized = imagecreatetruecolor($this->resize_to_width, $this->resize_to_height);
imageantialias($this->image_resized, true);
imagealphablending($this->image_resized, false);
imagesavealpha($this->image_resized,true);
$transparent = imagecolorallocatealpha($this->image_resized, 255, 255, 255, 127);
imagefilledrectangle($this->image_resized, 0, 0, $this->resize_to_width, $this->resize_to_height, $transparent);
imagecopyresampled($this->image_resized, $this->image, 0, 0, 0, 0, $this->resize_to_width, $this->resize_to_height, $this->width, $this->height);
if($resample == true){
$this->image = $this->image_resized;
$this->width = $this->resize_to_width;
$this->height = $this->resize_to_height;
$this->image_resized = "";
$this->resize_to_width = "";
$this->resize_to_height = "";
}
}
function save($folder_dir, $name){
if(is_dir($folder_dir)){
if($this->type == 'jpeg')
imagejpeg($this->image, $folder_dir . '/' . $name . '.jpg', 100)
or die('Image error');
elseif($this->type == 'png')
imagepng($this->image, $folder_dir . '/' . $name . '.png')
or die('Image error');
elseif($this->type == 'gif')
imagegif($this->image, $folder_dir . '/' . $name . '.gif')
or die('Image error');
}
else
return false;
return true;
}
}
?>
答案 0 :(得分:0)
/var/tmp/phpaFbMJV' is not a valid JPEG file
phpaFbMJV显然不是JPEG文件?
答案 1 :(得分:0)
您提供的文件无效请检查文件。只有扩展名.jpg不一定是有效的jpg格式图像。
答案 2 :(得分:0)
一旦尝试查找漏洞利用的某个用户轻易覆盖内容类型标头,我建议您使用imagecreatefromstring打开文件。
$this->image = @imagecreatefromstring(@file_get_contents($this->temp_loc));
if ($this->image === false) {
throw new Exception("File is unreachable or not a supported image");
}
接下来,您希望保存图像格式。我建议您只使用一种格式,例如png,这样您的所有图片现在都属于同一类型,您不必再担心了。