0
遇到一些與ci上傳類有關的麻煩。 真的很累,但需要使我的截止日期如此,如果任何人都可以給我提示..上傳類CodeIgniter不能正常工作
奇怪的是我從指南的樣本作爲起點,但它似乎並不工作。
控制器
public function store()
{
$data = array();
$data['title'] = $this->input->post('title');
$data['text'] = $this->input->post('text');
$data['hidden'] = $this->input->post('hidden');
$config['upload_path'] = base_url().'user_files/pictures/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload'); //initialize
$this->upload->initialize($config);
$this->upload->do_upload('userfile');
$imageData = $this->upload->data();
$data['file'] = $imageData['file_name'];
if (!$data['hidden'])
{
$data['hidden'] = 0;
}
$data['created_at'] = date('Y-m-d H:s:i');
$data['updated_at'] = '0000-00-00 00:00:00';
$this->mdl_newsfeed->store($data);
redirect('news/newsfeed_c/index');
}
形式
<form method="post" action="<?php echo base_url();?>news/newsfeed_c/store" enctype="multipart/form-data">
<div class="input-group input-group-lg">
<span class="input-group-addon">Title</span>
<input type="text" class="form-control" name="title" required="required" >
</div>
<label for="text">Text:</label><br />
<textarea name="text" id="text" required="required" cols="80" rows="10"></textarea><br />
<input type="file" name="userfile" size="20" />
<input type="submit" value="Post" class="btn btn-primary btn-lg"/>
</form>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('text');
</script>
你是什麼意思似乎沒有工作!?嘗試使用'$ this-> upload-> display_errors()獲取錯誤;' – goseo 2014-10-09 03:53:49
顯然,上傳文件夾的路徑不正確。 如果上傳腳本似乎不起作用,我想這很明顯是什麼問題;) – Maarten 2014-10-09 03:58:57
爲什麼你把base_url()作爲$ config ['upload_path']的開頭?它應該是Web服務器可以'寫'文件的文件路徑。 – 2014-10-09 04:22:10