Welcome Guest, Not a member yet? Register   Sign In
function in controller not working. Could be a problem with URL?
#1

[eluser]Zombie1[/eluser]
Hello all,

I'm having trouble with codeigniter. I only downloaded it yesterday and have been working my way through the tutorials.

I'm having some problems with my controllers. I've tried the basic 'blog' tutorial controller which works fine but when I try either the 'upload' or 'form validation' tutorials the controller does not recognise any of the functions, for example, when I try the upload tutorial, when I upload a file it doesn't recognise the 'do_upload' function within my upload.php file.

I get this error message:

The requested URL /Codeigniter/upload/do_upload was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Here's the code:

Code:
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);
  }
}
}

And in my 'upload_form.php' page inside my 'views' folder is this code:

Code:
<?php echo $error;?>
<?php

  echo form_open_multipart('upload/do_upload');?>

  <input type="file" name="userfile" size="20" />
  <br /><br />
  &lt;input type="submit" value="upload" /&gt;

&lt;?php echo form_close(); ?&gt;
My root folder is; 'http://localhost/Codeigniter/index.php/upload/' this works fine but when I press the upload button the url changes to: 'http://localhost/Codeigniter/upload/do_upload'. This may be the problem but I'm new to Codeigniter so can anyone help? Thanks in advance.


Messages In This Thread
function in controller not working. Could be a problem with URL? - by El Forum - 06-24-2014, 02:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB