[eluser]mindSmile[/eluser]
Hi everyone. I'm making an edit form that includes both text information and 2 file uploads, the first is a zip, the second is an image. So far I have the text updating fine, but the file uploading isn't working. First, I accidentally had a regular form_open instead of form_open_multipart, and when it was form_open, I could see the name of the file selected by logging it with firephp, but it was giving the error "You did not select a file to upload". When I saw that I needed to change it to form_open_multipart, the form started ignoring any file input areas altogether, and I could no longer see the name of the file selected. Using $this->output->enable_profiler(TRUE); I see that it is gathering the other POST data from the text fields, but I'm not even getting the "You did not select a file" error anymore, and none of the files are being uploaded.
I've checked file permissions on the source and the destination. It's still working perfectly in my "add" form where a new item is created instead of being updated. I don't need anything about the uploaded file to be added to my database, I just need to use my script to move the file to where it needs to be once the darn thing will upload. I haven't been trying to upload a new image file yet, so you won't see a do_upload() for that field at this point.
Here's the code (doing my best to only include the relevant parts)
View
Code:
<?php
$hidden = array(
'id' => $book->id,
'title_slug' => $book->title_slug
);
$form_dest = 'admin/update_book/';
echo form_open_multipart($form_dest, '', $hidden);
?>
<label for="order_title">Title - Shortened: </label>
<?php
$data = array(
'name' => 'order_title',
'id' =>'order_title',
'value' => $book->order_title,
'maxlength' => '255',
'size' => '50');
echo form_input($data);
?>
<label for="author">Author: </label>
<?php
$data = array(
'name' => 'author',
'id' =>'author',
'value' => $book->author,
'maxlength' => '255',
'size' => '50'
);
echo form_input($data);
?>
<label for="zipped_book">Zipped Book File:</label>
<?php
$data = array(
'name' => 'zipped_book',
'id' =>'zipped_book'
);
echo form_upload($data);
?>
<label for="cover_path">Cover Art:</label>
<?php
$data = array(
'name' => 'cover',
'id' => 'coverart',
);
echo form_upload($data);
?>
<label for="level">Is this file ready to be published on the site?</label>
<?php
$options = array(
'0' => 'Uploaded Only',
'1' => 'Tested, Awaiting Approval',
'2' => 'Approved and Published'
);
echo form_dropdown('level',$options,'0');
?>
<?php echo form_submit('submit','Update this Book','id="submit" class="blue_button"'); ?>
Controller
Code:
class Admin extends Controller{
function update_book(){
$this->load->model('Admin_model');
$data = $this->Admin_model->update_book();}
}
Model
[code]
class Admin_model extends Model{
function update_book(){
$id = $this->input->post('id');
$book = $this->Books_model->getBookByID($id);
$language = $this->Books_model->langCodeToLang($book->lang);
$slug = $book->title_slug;
$language = strtolower($language);
$file_path = realpath(APPPATH . '../assets/books/'.$language.'/'.$slug .'/');
$coverpath = $file_path . 'cover.jpg';
$this->load->library('upload');
$this->load->helper('file');
$this->output->enable_profiler(TRUE);
$new_file = $this->input->post('zipped_book');
if($new_file != ''){
//Delete the Current Files
if(is_dir($file_path)){
delete_files($file_path,TRUE);
rmdir($file_path);
}
//Upload the Zipped Folder
//Configure the Zipped Book Upload
$zipped_book = array(
'upload_path' => realpath(APPPATH . '../assets/books/'.$language.'/'),
'allowed_types' => 'zip',
);
//Do the Upload
$this->upload->initialize($zipped_book);
$field_name = 'zipped_book';
if($this->upload->do_upload($field_name)){
$book_data = $this->upload->data();
$upload_path = $book_data['full_path'];
}else {
$error = $this->upload->display_errors();
$this->firephp->warn($error); }
}
$new_cover = $this->input->post('cover');
if($new_cover != ''){
$this->firephp->log('A new cover is being uploaded.');
}
}