Welcome Guest, Not a member yet? Register   Sign In
Optional file upload
#1

first question:

Why the file upload in COdeigniter is not optional so that I need to make a trick?

Second one:

In this code below If I select a file it says "You did not select a file to upload." and doesn't upload.
I have title,text,date and file fields in the form.

If I don't select a file there is no problem. Can you help me solve that?


PHP Code:
public function create()
    {
        
$this->load->helper('form');
        
$this->load->library('form_validation');

        
$this->form_validation->set_rules('title''Başlık''trim|required');
        
$this->form_validation->set_rules('text''Yazı''trim|required');
        
        
$page="create";
        
        if (
$this->form_validation->run() === FALSE)
        {
            
$this->show($page);
        }
        else
        {
            
$title=$this->input->post('title');
            
$text=$this->input->post('text');
            
$date=$this->input->post('date');
            
$f=$this->input->post('file');
            
//$this->load->library("uploader");
            
if ($_FILES['dosya']['name'] != ""){
                
$this->uploadfile();
            }else{
                
$message="added without file successfully";
                
$data['title']="Makale Listesi";
                
$data['list']=$this->makale_model->listing(0);
                
$data['page']=$page;
                
$data['message']=$message;
                
$this->show("modify",$data);
            }
            
            
            
//$this->makale_model->insert($title,$text,$f,$date);
            //$f=$data['']
        
}
    }

private function 
uploadfile()
    {
        
$config['upload_path'] = base_url().'/files/makaleler/';
        
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg|pdf|doc|docx|ppt|pptx';
        
//$config['max_size']    = '100';
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';

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

            
$this->show("create",$error);
        }
        else
        {
            
$data = array('upload' => $this->upload->data());
            
$message="added successfully with file";
            
            
/*$data['title']="Listing";
            $data['list']=$this->makale_model->listing(0);
            $data['page']=$page;
            $data['message']=$message;
            $this->show("list",$data);
            */
            
$message=urlencode($message);
            
//redirect("makale/index?message=".$message,"refresh");
            
$this->show("modify",$data);
        }
    } 
Reply


Messages In This Thread
Optional file upload - by PolatAlemdar - 01-07-2015, 10:31 AM
RE: Optional file upload - by mwhitney - 01-07-2015, 01:07 PM
RE: Optional file upload - by PolatAlemdar - 01-08-2015, 09:02 AM
RE: Optional file upload - by mwhitney - 01-08-2015, 09:10 AM
RE: Optional file upload - by PolatAlemdar - 01-09-2015, 07:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB