我有一个定制的CMS网站,花了很长时间才建成。该网站过去在共享主机中工作正常。我刚把它移到VPS,由于某种原因图像不会上传。我检查了所有类型的解决方案,甚至取消了第一个VPS帐户,但第二个给出了同样的问题。所以我认为它不是关于托管。
我认为我的 process_image.php 存在问题。我认为这与Uploading file via PHP, doesn't work上的这个问题类似。这是代码:(我知道它的代码非常长,但任何帮助都会受到影响。我有一个星期不眠之夜。请给我一些建议。问候)
function Process_image() {
parent::__construct();
$this->load->library('image_lib');
//Generate random Activation code
function generate_code($length = 10) {
if ($length <= 0) {
return false;
}
$code = "";
$chars = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
srand((double)microtime() * 1000000);
for ($i = 0; $i < $length; $i++) {
$code = $code . substr($chars, rand() % strlen($chars), 1);
}
return $code;
}
}
function process_pic($image_path, $type='', $main=false, $width=175,$height=175 ) {
// $type
// 1-profile, 2-logo 3-events/news , 4-add
//
//Get File Data Info
$uploads = array($this->upload->data());
$this->load->library('image_lib');
if($type=='logo') {
return $this->generate_logo($image_path);
}
else {
//Move Files To User Folder
foreach($uploads as $key[] => $value) {
//Gen Random code for new file name
$randomcode = generate_code(32);
$newimagename = $randomcode.$value['file_ext'];
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $value['full_path'];
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_tn';
//$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
if($type=='profiles' ) {
$config['width'] = 100;
$config['height'] = 100;
}
else if($type=='profiles' || $type=='registered_slides' ||
$type=='registered_themes' ) {
$config['width'] = 75;
$config['height'] = 75;
}
else if($type=='favicon') {
if($value['image_width']>32) $config['width'] = 32; else
$config['width'] = $value['image_width'];
if($value['image_height']>32) $config['height'] = 32; else
$config['height'] = $value['image_height'];
}
else if($type=='logo') {
if($value['image_width']>250) $config['width'] = 250; else
$config['width'] = $value['image_width'];
if($value['image_height']>50) $config['height'] = 50; else
$config['height'] = $value['image_height'];
}
else if($type=='bsl_ads') {
$config['width'] = 100;
$config['height'] = 100;
}
else if($type=='product_images') {
$config['width'] = 80;
$config['height'] = 80;
}
else {
$config['width'] = $width;
$config['height'] = $height;
}
$config['new_image'] =$image_path. $newimagename;
/* Watermarking Configuration */
$config['wm_text'] = 'Copyright 2006 - SIMPRO';
$config['wm_type'] = 'overlay'; // Type of watermarking.
Options: text/overlay
$config['wm_font_path'] = 'arialbd.ttf'; // TT font
$config['wm_font_size'] = '12';
$config['wm_vrt_alignment'] = 'M'; // Vertical alignment: T M
B
$config['wm_hor_alignment'] = 'C'; // Horizontal alignment: L R
C
$config['wm_padding'] = '20'; // Padding around text
$config['wm_font_color'] = '#ffffff'; // Text color
//$this->image_lib->clear();
$this->image_lib->initialize($config);
//$this->load->library('image_lib', $config);
$this->image_lib->resize();
//$this->image_lib->watermark();
//Move Uploaded Files with NEW Random name
if($main) {
rename($value['full_path'],$image_path.$newimagename);
}
else {
unlink($value['full_path']);
}
//Make Some Variables for Database
$imagename = $newimagename;
$thumbnail = $randomcode.'_tn'.$value['file_ext'];
$filesize = $value['file_size'];
$width = $value['image_width'];
$height = $value['image_height'];
$timestamp = time();
//Add Pic Info To Database
$data = array(
'imagename'=>$imagename,
'thumbnail'=>$thumbnail,
'filesize'=>$filesize,
'width'=>$width,
'height'=>$height,
'timestamp'=>$timestamp
);
//Insert Info Into Database
//
return $data;
}
}
}
function generate_logo($image_path) {
//Get File Data Info
$uploads = array($this->upload->data());
$this->load->library('image_lib');
//Move Files To User Folder
foreach($uploads as $key[] => $value) {
//Gen Random code for new file name
$randomcode = generate_code(32);
$newimagename = $randomcode.$value['file_ext'];
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $value['full_path'];
$config['create_thumb'] = false;
$config['thumb_marker'] = '_tn';
//$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
if($value['image_width']>250) $config['width'] = 250; else $config['width'] = $value['image_width'];
if($value['image_height']>50) $config['height'] = 50; else $config['height'] = $value['image_height'];
$config['new_image'] =$image_path. $newimagename;
//$this->image_lib->clear();
$this->image_lib->initialize($config);
//$this->load->library('image_lib', $config);
$this->image_lib->resize();
//Move Uploaded Files with NEW Random name
$logo_name = $this->registered_userid.$value['file_ext'];
$source = $image_path. $newimagename;
$destination = $image_path.$logo_name;
if(file_exists($destination))
{ unlink($destination); }
rename($source, $destination);
// copy($source,$destination);
unlink($value['full_path']);
// die();
//Make Some Variables for Database
$imagename = $newimagename;
$thumbnail = $randomcode.'_tn'.$value['file_ext'];
$filesize = $value['file_size'];
$width = $value['image_width'];
$height = $value['image_height'];
$timestamp = time();
//Add Pic Info To Database
$data = array(
'imagename'=>$logo_name,
'thumbnail'=>$logo_name,
'filesize'=>$filesize,
'width'=>$width,
'height'=>$height,
'timestamp'=>$timestamp
);
//Insert Info Into Database
//
return $data;
}
}
function process_bannar_pic($image_path, $image_id, $thumbnail=FALSE) {
//Connect to database
$this->load->database();
//Get File Data Info
$uploads = array($this->upload->data());
$this->load->library('image_lib');
//Move Files To User Folder
foreach($uploads as $key[] => $value) {
//Gen Random code for new file name
$randomcode = generate_code(32);
$newimagename = $randomcode.$value['file_ext'];
//Creat Thumbnail
if($thumbnail) {
$config['image_library'] = 'GD2';
$config['source_image'] = $value['full_path'];
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_tn';
$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
$config['width'] = 175;
$config['height'] = 175;
}
$config['new_image'] =$image_path. $newimagename;
/* Watermarking Configuration */
$config['wm_text'] = 'Copyright 2006 - SIMPRO';
$config['wm_type'] = 'overlay'; // Type of watermarking. Options: text/overlay
$config['wm_font_path'] = 'monofont.ttf'; // TT font
$config['wm_font_size'] = '12';
$config['wm_vrt_alignment'] = 'M'; // Vertical alignment: T M B
$config['wm_hor_alignment'] = 'C'; // Horizontal alignment: L R C
$config['wm_padding'] = '20'; // Padding around text
$config['wm_font_color'] = '#ffffff'; // Text color
//$this->image_lib->clear();
$this->image_lib->initialize($config);
//$this->load->library('image_lib', $config);
$this->image_lib->resize();
//$this->image_lib->watermark();
//Move Uploaded Files with NEW Random name
rename($value['full_path'],$image_path.$newimagename);
//Make Some Variables for Database
$imagename = $newimagename;
$thumbnail = $randomcode.'_tn'.$value['file_ext'];
$filesize = $value['file_size'];
$width = $value['image_width'];
$height = $value['image_height'];
$timestamp = time();
//Add Pic Info To Database
$data = array(
'imagename'=>$imagename,
'thumbnail'=>$thumbnail,
'filesize'=>$filesize,
'width'=>$width,
'height'=>$height,
'timestamp'=>$timestamp
);
//Insert Info Into Database
$this->db->where('id', $image_id);
$this->db->update('cms_images',$data);
}
}
}
?>