Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

codeigniter - You did not select a file to upload. PHP Code Igniter

I am trying to implement a post functionality and want to pick message and image from a php view. My message functionality is working good. But on image upload i receive an error You did not select a file to upload. This is my controller function

function post_func()
{
    session_start();
    echo $post_message=$_POST['post'];
    echo $share_with=$_POST['share_with'];
    echo $image=$_POST['image'];
    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';


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

This is my view.

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

<!--<form id="loginForm" action="../search/post_func" method="post" enctype="multipart/form-data" >-->
<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>

//other view items
            <?php
    echo form_close();
    ?> 

Please help me

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change:

$this->upload->do_upload()

To this:

$this->upload->do_upload('my_file_input_name')

and it will work!! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...