CodeIgniter Forums

Full Version: file upload controller
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]KrizzAngel[/eluser]
i cant get it to work Sad pls help.. here's my controller:
it keeps on saying "You did not select a file to upload."

Quote:
class admin extends Controller {

function admin(){
parent::Controller();
$this->load->helper('form');
}

function upload() {
$baseLoc= base_url();
$config['upload_path'] = $baseLoc."assets/Lessons/";
$config['allowed_types'] = 'swf|flv';
$chap = $this->input->post('chapnum');
$less= $this->input->post('lessnum');
$config['file_name'] = "lesson_".$chap;

$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('file'))
{
echo $this->upload->display_errors();
}
else
{
echo $this->upload->data();
}
}
}

and my view page:

Quote:<? echo form_open_multipart('admin/upload'); ?>
<input type="hidden" name="chapnum" value="<? echo $chapnumber; ?>" />
<input type="hidden" name="lessnum" value="<? echo $lessNum; ?>" />
<input type="file" name="vid" /><br />
<input type="submit" value="Next" />

El Forum

[eluser]Jan_1[/eluser]
Formular is sending to a function called "addLesson" in admin controller.... ?!

El Forum

[eluser]KrizzAngel[/eluser]
ooppsss.. typo error.. there changed it already.. the upload function still dont work.. Sad
cant upload my swf file arghh

El Forum

[eluser]flaky[/eluser]
Code:
if ( ! $this->upload->do_upload('file'))

change to

Code:
if ( ! $this->upload->do_upload('vid'))

El Forum

[eluser]KrizzAngel[/eluser]
oh XD damn forgot bout the field name.. oh another problem.. "The upload path does not appear to be valid." any tips on how can i specify absolute path, coz the destination folder is located outside system folder

El Forum

[eluser]flaky[/eluser]
instead of
Code:
$config[‘upload_path’] = $baseLoc.“assets/Lessons/”;

do

Code:
$config[‘upload_path’] = “./assets/Lessons/”;

El Forum

[eluser]KrizzAngel[/eluser]
"./assets/Lessons/" on what directory would this go??
my DIR looks like this:

www
-codeigniter
-assets
| -Lessons <-- i want to put the files here
-System
-Application
and so on

El Forum

[eluser]Zorancho[/eluser]
'./assets/Lessons/' is the absolute path, it will upload the files exactly where you want them. Without trying and testing the code, you wont learn much Smile

El Forum

[eluser]VinceVe[/eluser]
Btw check if your map has enough rights to upload into it Wink

El Forum

[eluser]KrizzAngel[/eluser]
oh my bad... tnx
Pages: 1 2