消息:未定义的索引:图像

时间:2013-11-21 14:03:05

标签: php codeigniter file-upload

我正在尝试实现帖子功能,并希望从php视图中选择消息和图像。我收到错误Message: Undefined index: image,虽然我已经在我的视图中定义了它。这是我的看法

<?php echo form_open_multipart('search/post_func');?>

<div id="your_post">
<div id="post_image">
<img   id ="post_img" src="<?php  echo $this->config->item('base_url'); ?><?php echo '/application/css/'. $img ?>"/>
</div>
<textarea name="post" rows="5" cols="30" placeholder="Share an update..." id="post_text" rows="2" value=""></textarea>
<div class="liveurl-loader"></div>
<div id="clip">
<input name="image" type="file" id="attach" />  <!--THIS IS IMAGE-->
</div>
 <div class="liveurl" id="edited">
            <div class="close" title="Entfernen"></div>
            <div class="inner">

                <div class="details">
                <div class="image" id="img_dis"> </div>
                        <div class="title" id="title"> </div>
                        <div class="description" id="desc"> </div> 

                    <div class="video"></div>
                </div>

            </div>
     </div>





<div id="wraper_thin">
<select name="share_with" class="select_this" >
<option value="public">Share with: public</option>
<option value="connections">Share with: connections</option>
</select>
<button id="share" type="submit">Share</button> 
</div>
</div>


</form> 

这是我发生问题的控制器功能

function post_func()
{
session_start();
echo $post_message=$_POST['post'];
echo $share_with=$_POST['share_with'];
echo $image=$_POST['image'];//ERROR IS HERE
if($image==null){
    echo "<br/>no image<br/>";  
}
else{
    ////////////////////////////////////////////////////////////////////////////////////////////////

        $config['upload_path'] = './application/css';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';

        $file = $_FILES['image']['image'];
        $this->load->library('upload', $config);


        $this->upload->initialize($config);



        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

            echo "<br/>";
            echo $this->upload->display_errors();
            echo "<br/> image error<br/>";
        }
        else
        {

            echo "<br/> reached <br/>";
            session_start();
            $this->membership_model->insert_images($this->upload->data(),$email);
            $data = array('upload_data' => $this->upload->data());

            echo "<br/ problem<br/>";
        }




    ///////////////////////////////////////////////////////////////////////////////////////////////
}
$public;
if($share_with=="public"){
    echo "1";
    $public=true;
}else{
    echo "0";
    $public=false;
}echo "-----------------------------<br/>";
echo $user=$this->session->userdata('user_identification');
$data = array 
        (
            'userid'=> $user,
            'public' => $public,
            'message' => $post_message,
            'picname' => "None"
        );
$this->load->model('membership_model');
$this->membership_model->add_message($data);
echo "</br>";
echo $user=$this->session->userdata('user_identification');
}

我对错误发生的原因感到困惑。请帮帮我。

1 个答案:

答案 0 :(得分:1)

这将是$_FILES

$image = $_FILES['image'];
print_r($image);

它将返回一个数组,因此您需要打印它。所有文件,您通过file类型上传的图像都将由$_FILES处理,并确保您的表单将是multipart喜欢

<form enctype='multipart/form-data'>
     <input type="file" name="image">
</form>