【发布时间】:2011-07-22 21:03:54
【问题描述】:
在尝试使用上传库时,我很难确定自己做错了什么/如何排除故障。我有一个包含多个字段(主要是文本)的表单,其中包含一个图像上传字段。输入文本字段的数据已正确填充到我的数据库中,但用户浏览要上传的图像文件未显示在我在根目录创建的文件夹中,其权限允许将其写入。非常感谢所有帮助。谢谢!
下面的部分视图:
<p>
<label for="uEventFillByDateTime">Event Fill-by Date/Time:</label>
<input type="text" id="uEventFillByDateTime" name="uEventFillByDateTime" />
</p>
<p>
<label for="uEventImage">Event Image:</label>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="uEventImage" size="20" id="uEventImage" />
</p>
<p>
<label for="uEventKeywords">Event Keywords:</label>
<textarea id="uEventKeywords" name="uEventKeywords"></textarea>
</p>
控制器调用:
public function createEvent() {
if( !empty( $_POST ) ) {
echo $this->event_model->createEvent();
}
}
型号代码:
public function createEvent() {
$this->image_path = realpath(APPPATH . 'event_images');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->image_path,
'max_size' => 2000,
'max_width' => 212,
'max_height' => 118
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
/*format date time from string to mysql */
$cdt = $this->input->post( 'cEventDateTime', true );
$cdtMySQL = date("Y-m-d H:i:s", strtotime($cdt));
/*format fill-by date time from string to mysql */
$cfdt = $this->input->post( 'cEventFillByDateTime', true );
$cfdtMySQL = date("Y-m-d H:i:s", strtotime($cfdt));
$data = array(
'event_name' => $this->input->post( 'cEventName', true ),
'event_datetime' => $cdtMySQL,
'event_fillbydatetime' => $cfdtMySQL,
'event_keywords' => $this->input->post( 'cEventKeywords', true ),
'event_notes' => $this->input->post( 'cEventNotes', true ),
'event_featured' => $this->input->post( 'cEventFeatured', true ),
'fk_venue_id' => $this->input->post( 'cEventVenue', true ),
'fk_eventtype_id' => $this->input->post( 'cEventType', true ),
'fk_eventlifecycle_id' => $this->input->post( 'cEventlifecycle', true ),
);
$this->db->insert( 'event', $data );
return $this->db->insert_id();
}
【问题讨论】:
标签: image codeigniter upload