2013-09-18 5 views
0

Пожалуйста, помогите! Я хочу загрузить файл с помощью codeigniter, но это вернется к ошибке. Это загрузчик:Ошибка при отправке по электронной почте

class Uploader extends CI_Model 
{ 
    function __construct() 
    { 
     parent::__construct(); 

     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip'; 
     $config['max_size']  = '8192'; // kbytes 
     $config['encrypt_name'] = TRUE; 

     $this->load->library('upload', $config); 
     $this->response = ''; 
     $this->success = TRUE; 
    } 

    /** 
    * Triggers upload 
    * returns the file's details on success or false 
    */ 
    function upload($field_name) 
    { 
     if (!$this->upload->do_upload($field_name)) 
     { 
      $this->success = FALSE; 
      $this->response = $this->upload->display_errors(); 
      return false; 
     } 
     else 
     { 
      $this->success = TRUE; 
      $this->response = $this->upload->data(); 
      return $this->response['file_name']; 
     } 
    } 
} 

И это сообщение об ошибке: конфигурации базы данных

A PHP Error was encountered 

Severity: Notice 

Message: Undefined property: Downloads::$required_empty 

Filename: core/Model.php 

Line Number: 51 

автозагрузки на. Пожалуйста, помогите мне.

+1

Как вы называете 'Uploader-> upload()'? Что такое 'Загрузки'? Где вы пытаетесь получить доступ к '$ required_empty'? –

ответ

0

вы пытались что-то вроде этого

<?php 

class Upload extends CI_Controller { 

    function __construct() 
    { 
     parent::__construct(); 
     $this->load->helper(array('form', 'url')); 
    } 

    function index() 
    { 
     $this->load->view('upload_form', array('error' => ' ')); 
    } 

    function do_upload() 
    { 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $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->load->view('upload_form', $error); 
     } 
     else 
     { 
      $data = array('upload_data' => $this->upload->data()); 

      $this->load->view('upload_success', $data); 
     } 
    } 
} 
?> 

вы можете получить больше здесь http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

The Загрузить Folder Вы будете нуждаться в папку для загруженных изображений. Создайте папку в корневой папке установки CodeIgniter называется загрузки и установить права доступа к файлам 777.

2

попробовать это

if($this->input->post()) 
{ 
    $file_element_name = 'image'; //this is the name of your input file. for example "image" 
    if ($_FILES['image']['name']!= "") 
    { 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip'; 
     $config['max_size']  = '8192'; 
     $config['remove_spaces']=TRUE; //it will remove all spaces 
     $config['encrypt_name']=TRUE; //it wil encrypte the original file name 
     $this->load->library('upload', $config); 

     if (!$this->upload->do_upload($file_element_name)) 
     { 
     $error = array('error' => $this->upload->display_errors()); 
     $this->session->set_flashdata('error',$error['error']); 
     redirect('controller_name/function_name','refresh'); 
     } 
     else 
     { 
     $data = $this->upload->data(); 
     return $data['file_name'];   
     } 
     $this->session->set_flashdata('msg','success message'); 
     redirect('controller_name/function_name','refresh'); 
    } 
    else 
    { 
     //if no file uploaded the do stuff here 
    } 
} 

пожалуйста, дайте мне знать, если вы сталкиваетесь с любой проблемой.

Смежные вопросы