任何人都可以告訴我,如何解決以下問題?如何jpeg圖像上傳問題在php
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;
}
}
?>
我們可以幫助你,如果你顯示你的代碼 – 2014-08-28 10:34:05
檢查GD庫是否安裝 http://php.net/manual/en/image.installation.php – Confused 2014-08-28 10:49:52
@Confused,GD安裝,因爲錯誤會是不同的,像'警告:一些功能已被禁用..' – 2014-08-28 10:52:43