[eluser]mpar612[/eluser]
Hi Everyone,
I have the two functions in the code below to upload files. artist_upload is to upload an image, bio_upload is to upload a Word doc or pdf. Both of these functions work well independently, but when I put them together the first one (artist_upload) works fine, but bio_upload kicks out an error. By doing a print_r($this->upload->data('file_name')) on the file uploaded for bio_upload, I see that the $this->upload->data('file_name') is combining elements of the artist_upload image and the bio_upload.
I am still pretty new to codeigniter. Does anyone have any thought on how to resolve this? Is there a better way for me to go about doing this? I have a dozen more file uploads to add to this same page, so it's crucial that I have this working properly.
Thanks in advance!
Code:
public function artist_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '70000';
$config['max_width'] = '160';
$config['max_height'] = '100';
$this->load->library('upload', $config);
if (isset($_FILES['artist_image']) && !empty($_FILES['artist_image']['name']))
{
if ($this->upload->do_upload('artist_image'))
{
// set a $_POST value for file for use in db query
$_POST['artist_image'] = $this->upload->data('file_name');
return true;
}
else
{
// display error because does not meet $config requirements
$this->form_validation->set_message('artist_upload', $this->upload->display_errors());
return false;
}
}
else
{
//display error because nothing was uploaded
$this->form_validation->set_message('artist_upload', "You must upload a .gif, .jpg or .png");
return false;
}
}
public function bio_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
//$config['allowed_types'] = 'application/msword|application/vnd.openxmlformats-officedocument.wordprocessingml.document|pdf';
$config['max_size'] = '70000';
$this->load->library('upload', $config);
if (isset($_FILES['bio']) && !empty($_FILES['bio']['name']))
{
if ($this->upload->do_upload('bio'))
{
// set a $_POST value for file for use in db query
$_POST['bio'] = $this->upload->data('file_name');
return true;
}
else
{
// display error because does not meet $config requirements
print_r($this->upload->data('file_name'));
$this->form_validation->set_message('bio_upload', $this->upload->display_errors());
return false;
}
}
else
{
//display error because nothing was uploaded
$this->form_validation->set_message('bio_upload_', "You must upload a .doc, .docx, or .pdf");
return false;
}
}