我正在尝试上传codeigniter中的文件,但它没有上传,即使或正在执行,也没有返回任何错误,只是给出了输出
string(9) "image/png“
下面是我的代码控制器:
$this->load->library('upload');
if($_FILES['categoryIcon']['tmp_name'])
{
$ext=end(explode(".",$_FILES['categoryIcon']['name']));
$filename=date('Ymdhis').rand().".".$ext;
$config['upload_path']=dirname($_SERVER["SCRIPT_FILENAME"])."/assets/images/categories/";
$config['upload_url']=base_url()."assets/images/categories/";
$config['file_name']=$filename;
$config['max_width'] = '2048';
$config['max_height'] = '2048';
$config['allowed_types'] = '*';
$this->upload->initialize($config);
if($this->upload->do_upload('categoryIcon'))
{
$data['categoryIcon']=$filename;
//$response=$this->ecommerce_model->add_new_category($data);
echo "uploaded";
}
else{
echo $this->upload->display_errors();
echo "not uploaded";
}
}查看页面
<form action="" method="post" enctype="multipart/form-data" class="practice_form"> <input type="file" name="categoryIcon" id="image" class="form-control" accept="image/*"><input type="submit" value="Save Category" class="btn btn-primary"/>
发布于 2015-01-28 00:14:26
我有一个上传文件,在那里你可以做的是<input type="file=" name="categoryIcon[]" multiple="multiple"/>,应该拿起它,你可以改变任何你想要的do_upload。
也会改变
此$config['upload_path'] = dirname($_SERVER["SCRIPT_FILENAME"])."/assets/images/categories/";
如果您的上传文件夹位于主目录中,则不需要目录名。请参阅用户指南http://www.codeigniter.com/user_guide/libraries/file_uploading.html
回显文件数据
'$file_info = $this->upload->data();‘
‘回显$file_info’文件名‘;’
只有一个例子适用于多个codeigniter上传。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller {
function index()
{
$this->get_list();
}
public function get_list() {
$this->load->view('upload_success');
}
function do_upload() {
$this->load->library('form_validation');
// You need to set a form set rules
//$this->form_validation->set_rules('name', 'Banner Name', 'required');
if ($this->form_validation->run()) {
$files = $_FILES;
$file_loop = count($_FILES['categoryIcon']['name']);
for($i= 0; $i < $file_loop; $i++) {
$_FILES['categoryIcon']['name'] = $files['categoryIcon']['name'][$i];
$_FILES['categoryIcon']['type'] = $files['categoryIcon']['type'][$i];
$_FILES['categoryIcon']['tmp_name'] = $files['categoryIcon']['tmp_name'][$i];
$_FILES['categoryIcon']['error'] = $files['categoryIcon']['error'][$i];
$_FILES['categoryIcon']['size'] = $files['categoryIcon']['size'][$i];
$this->upload->initialize($this->file_config());
if (!$this->upload->do_upload()) {
$this->get_form();
} else {
$filename = $files['categoryIcon']['name'][$i];
$this->get_list();
}
} else {
$this->get_form();
}
}
public function get_form() {
$data['error'] = $this->upload->display_errors('<div class="alert alert-info">', '</div>');
$this->load->view('upload_form', $data);
}
private function file_config() {
$config = array();
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = TRUE;
return $config;
}
} https://stackoverflow.com/questions/28171263
复制相似问题