繁体   English   中英

codeigniter->上传空问题

[英]codeigniter -> Upload Null Issue

我收到以下错误:

Column 'thumbpath' cannot be null

我已经尝试过$thumb_info = $thumb_info = $this->image_lib->resize(); 然后在我的$data数组中将其设置为'thumbpath' => $thumb_info['create_thumb']但这会导致PHP错误

Fatal error: Call to a member function resize() on a non-object in addimage.php on line 60

我也很努力地将错误或成功消息发布到视图中:

视图

<?php
    //Setting form attributes
$formAddImage = array('id' => 'addImage', 'name' => 'addImage');
$imageImage = array('id' => 'userfile', 'name' => 'userfile', 'placeholder' => 'File Location*');
$imageDescription = array('id' => 'description','name' => 'description','placeholder' => 'Image Description*');
?>
<section id = "validation"><?php echo validation_errors();?></section>

<?php
if(!empty($success)) : ?>

<section id="validation"><?php echo $success; ?></section>

<?php endif; ?>

<?php
echo form_open_multipart('admin/addimage', $formAddImage);
echo form_fieldset();
echo form_upload($imageImage);
echo form_textarea($imageDescription);
echo form_submit('submit','Submit');
echo form_fieldset_close();
echo form_close();
?>`

控制者

 if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Addimage extends CI_Controller { 

function __construct(){ 
parent::__construct(); 
} 
function index() { 
if(!$this->session->userdata('logged_in')) { 
    redirect('admin/home'); 
} 
// Main Page Data 
$data['cms_pages'] = $this->navigation_model->getCMSPages(); 
$data['title'] = 'Add Gallery Image'; 
$data['content'] = $this->load->view('admin/addimage',NULL,TRUE); 

$this->load->view('admintemplate', $data); 

//Set Validation 
//$this->form_validation->set_rules('userfile', 'userfile', 'trim|required'); 
$this->form_validation->set_rules('description', 'Description', 'trim|required'); 

if($this->form_validation->run() === TRUE) { 

//Set File Settings 
$config['upload_path'] = 'includes/uploads/gallery/'; 
$config['allowed_types'] = 'jpg|png'; 
$config['max_size'] = '100'; 
$config['max_width'] = '1024'; 
$config['max_height'] = '768'; 

$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {

$error = array('imageError' => $this->upload->display_errors());
$this->load->view('admintemplate', $data); 
}
else{
$data = array('upload_data' => $this->upload->data());
$config['image_library'] = 'GD2';
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config['new_image'] = 'includes/uploads/gallery/thumbs/';
$config['create_thumb'] = 'TRUE';
$config['maintain_ratio'] = 'FALSE';
$config['width'] = '200';
$config['height'] = '150';

$this->load->library('image_lib', $config);
$this->image_lib->resize();
}

$file_info = $this->upload->data();

$data = array(   
    'description' => $this->input->post('description', TRUE), 
    'fullpath' => $file_info['file_name'],
'thumbpath' => $file_info['create_thumb']
    ); 
$this->image_model->addImage($data);

$this->data['success'] = 'Thank You, Your Image Has Been Uploaded';
} 
} 

}

模型

function addImage($data) {
    $this->db->insert('images',$data);
    return;
}

在第58行:

'thumbpath' => $file_info['create_thumb']

我不认为'create_thumb'是来自$ this-> upload-> data()的有效字段

也许你想要:

 'thumbpath' => $config['new_image'].$this->upload->file_name  

好的-关于正确设置拇指路径的第二个问题,我认为您需要这样的东西:

$imagefullpath = $config['new_image'].$this->upload->file_name;
$path_parts = pathinfo($imagefullpath);
$imageextension = $path_paths['extension'];
$imagerenamed = $part_parts['dirname'].'/'.$path_parts['filename'].'_thumb'.$imageextension;

(未经测试,请确保您至少运行PHP 5.2)

让我知道结果如何。

我通过执行以下操作解决了此问题:

    $data = array(   
    'description' => $this->input->post('description', TRUE), 
    'fullpath' => $file_info['file_name'],
'thumbpath' =>$file_info['raw_name'].'_thumb'.$file_info['file_ext'] 
    ); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM