duanqian8867 2013-11-21 14:03
浏览 47
已采纳

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

I am trying to implement a post functionality and want to pick message and image from a php view. I am receiving an error Message: Undefined index: image although i have defined it in my view. this is my view

<?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> 

this is my controller function where the problem is occurring

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');
}

I am confused about why the error is happening. Please HELP me.

  • 写回答

1条回答 默认 最新

  • dsh125986083 2013-11-21 14:04
    关注

    It will be $_FILES

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

    It will return an array so you need to print it.All the files,images which you are upload through the file type they all will be handeled by $_FILES and makesure that your form will be multipart like

    <form enctype='multipart/form-data'>
         <input type="file" name="image">
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程