[eluser]Unknown[/eluser]
Hey guys,
So the issue isn't as bad as it seems. What i'm trying to do is set up my uploader so that when a user chooses a file (say a zip file) and a picture, it uploads the file to one folder, and the picture to a seperate directory.
I've kinda got it working. where it'll accept both files. but it'll only upload one.
the error i'm getting is that it'll say the upload worked, but only the one that was uploaded first will upload( I.E if it uploads the file first, the picture will fail. and vice versa)
Has anybody had a similar issue? is it even possible to upload 2 items to seperate directories with the uploader class?
I've attached a copy of the functions used in the controller as well as the view:
Uploader controller
Code:
$this->form_validation->set_rules('add[name]', 'Name', 'required');
$this->form_validation->set_rules('add[type]', 'Type', 'required');
$this->form_validation->set_rules('add[created]', 'Created', 'required');
$this->form_validation->set_rules('add[description]', 'Description', 'required');
if($this->form_validation->run())
{
$path = './files/download/' . $_POST['add']['type'];
$types = 'zip';
$name = $_POST['add']['name'] . '_' . $_POST['add']['created'] . '.zip';
$field = 'upload_file';
if($this->_upload_file($path, $types, $field, $name))
{
$this->load->view('alertify/success', array('message' => 'File Uploaded Successfully'));
}//end if
else
{
$this->load->view('alertify/error', array('message' => $error));
}//end else
}//end if
//upload_file function
public function _upload_file($path, $types, $field, $name = null)
{
$config['upload_path'] = $path;
$config['allowed_types'] = $types;
if($name !== null)
{
$config['file_name'] = $name;
}//end if
$this->load->library('upload', $config);
if($this->upload->do_upload($field))
{
return true;
}//end if
$error = $this->upload->display_errors();
return $error;
}//end upload_file
Upload View
Code:
<?php defined('BASEPATH') or exit; ?>
<div class="row">
<div class="main_content">
<?php print form_open_multipart('Admin/add_content/portfolio'); ?>
<fieldset>
<legend>Add to your portfolio</legend>
<?php
if(validation_errors('', ''))
{ ?>
<div class="form_errors">
<?php print validation_errors('<div class="errors">', '</div>'); ?>
</div>
<?php }//end if
?>
<div class="row">
<div class="small-7 columns">
<label for="add[name]">Name</label>
<input type="text" name="add[name]" placeholder="Name" />
</div>
</div>
<div class="row">
<div class="small-7 columns">
<label for="add[type]">Type</label>
<select name="add[type]">
<option value="web">Web</option>
<option value="java">Java</option>
<option value="c++">C++</option>
</select>
</div>
</div>
<div class="row">
<div class="small-7 columns">
<label for="add[created]">Created On</label>
<input type="text" name="add[created]" id="datepicker" />
</div>
</div>
<div class="row">
<div class="small-7 columns">
<label for="upload_file">Add a file</label>
<input type="file" name="upload_file" />
</div>
</div>
<div class="row">
<div class="small-7 columns">
<label for="upload_picture">Add a Screenshot</label>
<input type="file" name="upload_picture" />
</div>
</div>
<div class="row">
<div class="small-7 columns">
<div class="textarea">
<label for="add[description]">Description</label>
<textarea rows="50" cols="50" name="add[description]" placeholder="What does it do?"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="small-4 columns">
<input type="submit" name="article[submit]" value="Add" class="button" />
</div>
</div>
</fieldset>
<?php print form_close(); ?>
</div>
</div>
Sorry if this is in the wrong section or if i've left something out. i've been trying to find a way to solve this issue for a while. but nothing seems to be working. Also thanks in advance to any help received. it's greatly appreciated