$ _FILES在CodeIgniter中为空 [英] $_FILES is empty in CodeIgniter
本文介绍了$ _FILES在CodeIgniter中为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用CodeIgniter开发表单.在这种情况下,字段之一是上传文件.我成功地遵循了一些有关在CodeIgniter中上载文件的教程,但是在我的工作中,$ _ FILES始终为空,我不知道为什么.我是这个框架中的新手.
I'm developing a form using CodeIgniter. In this, one of the fields is to upload a file. I followed some tutorials about file uploading in CodeIgniter successfully, but, in my work, the $_FILES is always empty, and I can't see why. I'm a newbie in this framework.
视图:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
$this->load->helper('form');
echo form_open_multipart($action); ?>
Área:
<select>
<option value="1">Teste 1</option>
<option value="2">Teste 2</option>
</select> <br>
Data de abertura: <input type="text" id="data_abertura" placeholder="tqv"> <br>
Prioridade:<br>
<input type="radio" name="prioridade" value="3">Alta<br>
<input type="radio" name="prioridade" value="2">Média<br>
<input type="radio" name="prioridade" value="1">Baixa<br>
Anexar arquivo: <input type="file" accept="image/*, text/*, .doc, .docx, .pdf" name="arquivo" id="arquivo"><br>
Descrição: <br><textarea rows="4" cols="50" id="descricao" name="descricao"></textarea><br>
<input type="submit" id="enviar" name="enviar" value="Enviar">
<?php echo form_close() ?>
</body>
</html>
控制器:
<?php
class c_Formulario extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$data['action'] = site_url('c_formulario/inserir_dados');
$this->load->view('v_formulario', $data);
}
public function inserir_dados()
{
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|doc|docx|pdf|txt';
$config['max_size'] = '100';
$this->load->library('upload');
$this->upload->initialize($config);
var_dump($_FILES);
foreach($_FILES as $field => $file)
{
//var_dump($_FILES); die();
// No problems with the file
if($file['error'] == 0)
{
// So lets upload
if ($this->upload->do_upload($field))
{
$data = $this->upload->data();
echo $data['full_path'];
}
else
{
$errors = $this->upload->display_errors();
var_dump($errors);
}
}
}
$this->load->model('m_formulario', '', TRUE);
$area = array('id' => null, 'nome' => $this->input->post('area', TRUE));
$data = array('id' => null, 'dataabert' => $this->input->post('data_abertura', TRUE));
$prioridade = array('id' => null, 'nome_prioridade' => $this->input->post('prioridade', TRUE));
$arquivo = array('id' => null, 'urlarquivo' => $this->input->post('arquivo', TRUE));
$descricao = array('id' => null, 'descricao' => $this->input->post('descricao', TRUE));
$dados = array
(
'area' => $area,
'data' => $data,
'prioridade' => $prioridade,
'arquivo' => $arquivo,
'descricao' => $descricao
);
$this->m_formulario->inserir($dados);
}
谢谢您!
推荐答案
我不知道为什么,但是更改允许的类型可以解决此问题. $ config ['allowed_types'] ='*';我正在测试一些txt和png文件.好吧,现在还可以.不好意思,这个问题.
I don't know exactly why, but changing the allowed types I solved the issue. $config['allowed_types'] = '*'; I was testing with some txt and png files. Well, it's ok now. Sorry the bad question.
这篇关于$ _FILES在CodeIgniter中为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文