codeigniter图片上传中的未定义索引图片

时间:2015-08-31 16:29:27

标签: php image codeigniter upload

嘿guyx我正在尝试在codeingniter中上传图像,但它一直给我一个这样的错误

A PHP Error was encountered

Severity: Notice

Message: Undefined index: pic

Filename: controllers/dou.php

Line Number: 7

我的上传视图

<!DOCTYPE html>
<html>
<head>
    <title>Upload form</title>
</head>
<body>
<?php echo form_open('dou/upload');?>

<?php echo form_upload('pic'); ?>
    <?php echo form_submit('submit','Save');?>
<?php echo form_close();?>
</body>
</html>

我的控制器

<?php 
    class DoU extends XM_Controller {
        public function index(){
            $this->load->view('upload_view1',array('error' => ''));
        }
        public function upload(){
            if(is_uploaded_file($_FILES['pic']['tem_nam'])) {
                move_uploaded_file($_FILES['pic']['tem_nam'], './assets'.$_FILES['pic']['name']);
            }
        }
    }

任何帮助将不胜感激..

我已经尝试打印数组“$ _FILES”,但它完全是空的 我做错了什么?

1 个答案:

答案 0 :(得分:1)

您应该使用:

form_open_multipart()

功能,因为你有文件上传

来自文件:https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html(实际上也是CI3)