[eluser]jmbatty[/eluser]
Let me start by saying that I thorougly searched the forum about this error. I tried all the suggestions. with no luck.
here is the story.
I'm starting on codeigniter and decided to migrate portions of my existing site to it, in the learning process. I went through the user_guide, the upload tool example on nettuts (on a different machine.)
I code on mac, with MAMP.
my codeigniter works wonders, and I'm building a forum as the first significant project.
I have the portion of code below that is just killing me.
a view with a form as below
Code:
<form action="http://localhost/codeigniter/index.php/users/avatarupload" method="post" class="loginForm" enctype="multipart/form-data"><br/><input type="file" name="users_avatarFile" value="" id="users_avatarFile" /><br /><input type="submit" name="submit" value="Upload !" /></form>
the controller is as follows:
Code:
/***** controller ****/
function avatarupload() {
$this->load->helper('file');
$config['uploadpath']='./images/';
$config['allowed_types']='gif|jpg|png';
$config['max_size']='3000';
$config['max_width']='1024';
//testing purposes
if ( !write_file($config['uploadpath'].'file34.txt', 'test test test test'))
{
$mytest= 'Unable to write the file';
}
else {
$mytest= 'File written!';
}
$this->load->library('upload');
$this->upload->initialize($config);
// note: $this->load->library('upload', $config); has the same results
if ( ! $this->upload->do_upload('users_avatarFile')){
$this->session->set_flashdata('error', "test write: $mytest<br />path: ".$config['uploadpath'].'
<br/>Could not upload the photo for the following reason:<br/>'.$this->upload->display_errors().' <br />Try again.');
redirect('/users/','location');
}
else{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
/*** result : **************************
output:
Error :
test write: File written! // and yes, the file is created with the correct content in the correct folder.
path: ./images/
Could not upload the photo for the following reason: // that's the error I get with upload
The upload path does not appear to be valid. // tadaaa
Try again. // yeah.
**********/
So I can write_file to the folder, but I can't do_upload. "The upload path does not appear to be valid"
I tried many variations of $config['uploadpath'], with FCPATH, base_url, site_url, $_SERVER vars, everything. i tried to initialize($config), or not, same result.
No error in apache.log, or error.log
is_dir() returns that yes, it's a dir.
Folder is 777, and again, write_file just works.
what am I missing ?