[eluser]ShoeLace1291[/eluser]
I've gone over the article in the user guide on the file uploading class, but I just can't seem to figure out what I'm doing wrong. I'm combining both the db class and the upload class so users can upload a photo. I use the db class to later get the photos by the user id, etc. When I submit the form, it tells me that I did not select a file to upload. The database function executes properly, but the file itself doesn't upload.
Here is my controller:
Code:
<?php
class Photos extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->library('gallery/photo');
$this->load->library('gallery/album');
}
function upload(){
$member = $this->member->user_context();
$this->load->library('form_validation');
$this->template->overall_header($title = 'Upload Photo');
$this->form_validation->set_rules('album', 'Album', 'required');
$this->form_validation->set_rules('title', 'Title', 'required|min_length[5]|max_length[30]|xss_clean');
$this->form_validation->set_rules('caption', 'Caption', 'required|min_length[5]|max_length[150]|xss_clean');
if($this->form_validation->run() == FALSE){
$data = array(
'FORM_OPEN' => form_open_multipart('gallery/photos/upload/'),
'VALIDATION_ERRORS' => validation_errors(),
'MEMBER_ALBUMS' => $this->album->dropdown($member['id'], $this->uri->segment(4))
);
$this->parser->parse('gallery/photo_upload.tpl', $data);
} else {
$info = array(
'album_id' => $this->input->post('album'),
'title' => $this->input->post('title'),
'caption' => $this->input->post('caption'),
'author_id' => $member['id']
);
if($this->photo->upload_db($info)){
$config = array(
'upload_path' => 'attachments',
'allowed_types' => 'jpg',
'max_size' => 100,
'max_width' => 750,
'max_height' => 750,
'file_name' => $this->photo->insert_id.".jpg"
);
$this->load->library('upload', $config);
if($this->upload->do_upload()){
redirect('gallery/photos/'.url_title($this->input->post('title')).'/'.$this->photo->insert_id);
} else {
$data = array(
'ERROR_TITLE' => 'File Upload Error',
'ERROR_MESSAGE' => $this->upload->display_errors(),
'ERROR_TYPE' => 'bad'
);
$this->parser->parse('body_error.tpl', $data);
}
} else {
$data = array(
'ERROR_TITLE' => 'System Error',
'ERROR_MESSAGE' => 'The system encountered an error while updating the database with the necessary information.',
'ERROR_TYPE' => 'ok'
);
$this->parser->parse('body_error.tpl', $data);
}
}
}
}
Here is the form:
Code:
<div class="container">
<div id="content-left">
<div id="post" style='clear: both;'>
<h2>Upload Photo</h2>
<div class="half-last">
<div class="purelist arrows">
<ul>
{VALIDATION_ERRORS}
</ul>
</div>
</div>
{FORM_OPEN}
<p>
<label for="album">Album:</label>
{MEMBER_ALBUMS}
</p>
<p>
<label for="title">Photo Title: </label>
<input id="title" name="title" />
</p>
<p>
<label for="caption">Caption:</label>
<input id='caption' name='caption' />
</p>
<p>
<p>
<label for="file">Upload File:</label>
<input id='file' name='file' type='file' />
</p>
<p>
<input type="submit" value="Submit" id="submit-btn"/>
</p>
<div id="info"></div>
</form>
</div>
</div>
</div>