[英]codeigniter image upload cant grab file name
我試過嘗試,但我無法上傳我的圖像。 當我試圖回應它時,我無法獲取我的圖像名稱:S。
你能看出我做錯了嗎?
這是我的控制器:
<?php
//ADMIN PAGE
if (! defined('BASEPATH')) exit('No direct script access');
class News extends CI_Controller {
//Write post when logged in as admin
function write()
{
//insert image
$config['upload_path'] = APPPATH .'/archive/img/news/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '9000';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
$this->upload->do_upload('newsImage');
$file_data = $this->upload->data();
$newsData = array(
'headline' => $this->input->post('headline'),
'description' => $this->input->post('description'),
'content' => $this->input->post('content'),
'creater' => $this->session->userdata('username'),
'ip' => $this->session->userdata('ip'),
'imgPath' => $file_data['file_name']
);
echo "<pre>";
//print_r( $this->upload->data());
//print_r($file_data);
//print_r($_FILES);
//print_r($this->input->post());
print_r($newsData);
echo "</pre>";
$this->load->model('admin/news_model');
$this->news_model->insertNews($newsData);
$data['main_content'] = 'admin/write_view';
$this->load->view('template', $data);
}
}
我的視圖文件,我上傳我的圖像
<div id="inputStyle">
<?php
echo form_open_multipart('admin/news/write');
echo form_input('headline', 'overskrift');
echo form_upload('newsImage');
echo form_textarea('description', 'indhold');
echo form_textarea('content', 'content');
echo form_submit('create', 'Opret nyhed');
echo form_close();
?>
</div><!-- inputStyle -->
我已經編輯了你的代碼。 它可能適合你。 如果您的文件夾位於應用程序的根文件夾中,則無需使用APPPATH。 我也在你的代碼中對此進行了編輯。 嘗試這個。
//Write post when logged in as admin
function write()
{
//insert image
$config['upload_path'] = 'archive/img/news/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '9000';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
$this->upload->do_upload('newsImage');
$file_data = $this->upload->data();
$newsData = array(
'headline' => $this->input->post('headline'),
'description' => $this->input->post('description'),
'content' => $this->input->post('content'),
'creater' => $this->session->userdata('username'),
'ip' => $this->session->userdata('ip'),
'imgPath' => $_FILES['newsImage']['name']
);
echo "<pre>";
//print_r( $this->upload->data());
//print_r($file_data);
//print_r($_FILES);
//print_r($this->input->post());
print_r($newsData);
echo "</pre>";
$this->load->model('admin/news_model');
$this->news_model->insertNews($newsData);
$data['main_content'] = 'admin/write_view';
$this->load->view('template', $data);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.