Welcome Guest, Not a member yet? Register   Sign In
Help!! I can upload anything with codeigniter
#11

[eluser]InsiteFX[/eluser]
pickupman, is correct on the windows permissions.

The error is telling you that the upload library is not loaded!

Try to autoload the library.

InsiteFX
#12

[eluser]adekenny[/eluser]
thanks a lot.

I've autoloaded the "upload" library and the "form" helper as your suggested but it's still not working.

The error message i'm now getting is:

Unable to find a post variable called userfile.

I even tried renaming the form file to "username" and pass it as a post variable ($_FILE['userfile']['name']) to the controller but it kept saying the same thing. I later rename it back to $data as shown in the e-book i'm using but the proble persist.


Please see my view below:


<?php

$this->load->helper('form');
$this->load->helper('url');

echo @$errors;;

echo form_open_multipart('upload/do_upload');


echo form_upload($data);


echo form_submit('mysubmit', 'Submit Post!');

echo form_close();

?>



Also see my controller code:

function do_upload()
{

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


$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

$this->load->view('photo_upload_failed', $errors);
}
else
{
$data['myupload'] = array('upload_data' => $this->upload->$this->data());

$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

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



Thanks for all your help so far......but I still need more HELP to get this solved as i've done all i know to get the do_upload function to see the post variable called "userfile " but it's not just working.
#13

[eluser]adekenny[/eluser]
Please note: I was unable to pass the errors message as a an element of the array ($data) to the view ......So i had to pass only the $errors variable to the view.

I don't know why this is so....
#14

[eluser]pickupman[/eluser]
You are not creating your form field properly. See post #5. You will see I used:
Code:
echo '<p>'.form_label('Choose Image','userfile').'<br/>'.form_upload('userfile').'</p>';
#15

[eluser]adekenny[/eluser]
when i used the code i was getting the error message:

Fatal error: Call to undefined function form_label() in C:\Program Files (x86)\EasyPHP 2.0b1\www\system\application\views\photo_upload.php on line 39

so i changed it back to the previous version.
#16

[eluser]pickupman[/eluser]
You need to at least use:
Code:
form_upload('userfile');

You can't pass $data to the form_upload() field, as you have not properly set the variable to be your input.
#17

[eluser]adekenny[/eluser]
Thanks for all your help.....

i've amended it as you advised but the same error message is appearing.

Unable to find a post variable called userfile.


Do i need to change something in my controller or upload library?

class Upload extends Controller
{

var $base;
var $css;
var $my_menu;
var $userfile;

function Upload()
{
parent::Controller();
$this->base = $this->config->item('base_url');
$this->css = $this->config->item('css');
$this->load->library('menu');
$this->my_menu = $this->menu->show_menu();
$this->load->library('upload');
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
}


function do_upload()
{

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


$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

$this->load->view('photo_upload_failed', $errors);
}
else
{
$data['myupload'] = array('upload_data' => $this->upload->$this->data());

$data['menu'] = $this->my_menu;
$data['base'] = $this->base;
$data['css'] = $this->css;

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

}
#18

[eluser]pickupman[/eluser]
You have not set the variable $userfile in your class, constructor, or method
Code:
class Upload extends Controller
{
//Your declared variables
  function Upload()
  {
      parent::Controller();
      $this->base = $this->config->item(‘base_url’);
      $this->css = $this->config->item(‘css’);
      
      $this->userfile = 'userfile'; //Add this line

      $this->load->library(‘menu’);
      $this->my_menu = $this->menu->show_menu();
      $this->load->library(‘upload’);
      $this->load->library(‘session’);
      $this->load->helper(‘form’);
      $this->load->helper(‘url’);


  }

Also note, when posting code use the code button option at the top of the message box.
#19

[eluser]adekenny[/eluser]
Hurray!!!!!!

It's working very fine now - i can now upload images to a folder in my root folder.

Many thanks for all your help.

You guys are simply fastastic.......really appreciate your support.



adekenny - Nigeria




Theme © iAndrew 2016 - Forum software by © MyBB