Welcome Guest, Not a member yet? Register   Sign In
Uploads, with email confirmation
#1

[eluser]timj[/eluser]
Perhaps I am just not getting it. I want my Uploads utility to send an email confirmation to the webmaster that a file has indeed been uploaded. The following code does not seem to cut it. In fact, it breaks the upload_success View file (the file uploads, it just breaks the View). Pointers?

class Upload extends Controller {

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

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

function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '';
$config['max_width'] = '';
$config['max_height'] = '';

$this->load->library('upload', $config);

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

$this->load->view('upload/upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload/upload_success', $data);
$this->email->to('[email protected]', 'Webmaster');
$this->email->subject('A file has been added');

}
}
}
#2

[eluser]Milos Dakic[/eluser]
Check that all the libraries are loaded. You can use the CodeIgniter log to see if the library appears in the process. Also a suggestion would be to split the emailing functionality into a maybe private function to see if it makes a difference, as well as placing the email functionality above the load->view call as that might be a problem. See how you go with that. If the problem exists, please use a paste bin to paste your view code so that someone can have a more detailed look at everything.
#3

[eluser]timj[/eluser]
Those were some great suggestions. Tried them, but they did not work (not sure how to call the email as a private function under the same ELSE statement, would like the email to operate in tandem with the upload and be logically paired).

The Views file is standard, right out of the documentation.
#4

[eluser]Milos Dakic[/eluser]
Code:
class Upload extends Controller {
  function Upload() {
      parent::Controller();
      $this->load->helper(array(‘email’,‘form’,‘url’));
  }
  
  function index() {  
      $this->load->view(‘upload/upload_form’, array(‘error’ => ’ ’ ));
  }

  function do_upload() {
      $config[‘upload_path’] = ‘./uploads/’;
      $config[‘allowed_types’] = ‘gif|jpg|png’;
      $config[‘max_size’]  = ‘’;
      $config[‘max_width’]  = ‘’;
      $config[‘max_height’]  = ‘’;
      
      $this->load->library(‘upload’, $config);
  
      if ( ! $this->upload->do_upload()) {
        $error = array(‘error’ => $this->upload->display_errors());
        
        $this->load->view(‘upload/upload_form’, $error);
      }  
      else {
        $data = array(‘upload_data’ => $this->upload->data());  
        $this->_send_email();
        $this->load->view(‘upload/upload_success’, $data);

      }
    }
      function _send_email() {
        $this->email->to(‘[email protected]’, ‘Webmaster’);
        $this->email->subject(‘A file has been added’);
      }
}

Also noticed you named the controller the same name as the class as well as your upload method. Maybe try changing them to something else just to see what happens.




Theme © iAndrew 2016 - Forum software by © MyBB