codeigniter图片上传无法获取文件名 [英] codeigniter image upload cant grab file name
本文介绍了codeigniter图片上传无法获取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过尝试,但我无法上传我的图像。
当我试图回应它时,我无法获取我的图像名称:S。
i have try and try and i just cant get my image to upload. And i cant grab my image name when i try to echo it out :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);
}
}
我的观点我上传图片的文件
And my view file where i upload my image
<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。我也在你的代码中对此进行了编辑。试试这个。
I have edited your code. It may be work for you. If your folder is in root folder of application then no need to use APPPATH. I have also edited this in your code. Try this.
//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);
}
这篇关于codeigniter图片上传无法获取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文