Welcome Guest, Not a member yet? Register   Sign In
Yet another cry for help on file uploads
#1

[eluser]tim1965[/eluser]
Hi

I have a batch file upload script, that i have put together using this as a basis http://ellislab.com/forums/viewthread/80610/
The script is correctly uploading the files and generating thumbnails. I also upload a $_POST description field that is stored with the new file name in the daatabase. However i have a few problems that i cannot seem to work out how to deal with.

Firstly i need to associate any errors generated with the fields for display_errors. At the moment it correctly displays the errors but i cant seem to either associate a filename witht the error or split the array to associate the error message with the relevant field. e.g. on my form i may correctly upload five files, but a further two may fail. Currently all i can do is generate 2 failed upload errors on the form but dont know how to associate these with the filename or relevant field.

Secondly i need to ensure that only a certain number of files are uploaded for each directory.

Thirdly aa general question, should i fail and remove all uploads if one fails, and get the user to upload everything again.

I have been working on this for a while so probably cannot see the wood for the trees, so would appraciate anybodys time to help if possible.

My controller
<?php
class c_f_propreg3_multifileupload_v1 extends Controller
{

function Upload()
{
parent::Controller();
$this->load->helper(array('form','url','file'));
//$this->load->view('propreg/f_propreg3_multifileupload_v1');
}

function index()
{


$this->load->view('propreg/f_propreg3_multifileupload_v1', array('errors' =>' '), array('message' =>' ')); //Upload Form

}

function picupload()
{
//Load Model
$this->load->model('Process_image');

//get property id to create directory for pictures and thumbs
$prop = $this->session->userdata('propid');
$propid = $prop['prop_id'][0];

if (isset($_POST) && count($_POST) >0 )


//create directories for upload based on property id
$prop = $this->session->userdata('propid');
$propid = $prop['prop_id'][0];

$mypath = './system/pictures/'.$propid;
$main_pic = './system/pictures/'.$propid.'/pictures/';
$thumb_path = './system/pictures/'.$propid.'/thumbs/';

if (!is_dir($mypath))
{
mkdir($mypath,0777,TRUE);
}
if (!is_dir($main_pic))
{
mkdir($main_pic,0777,TRUE);
}
if (!is_dir($thumb_path))
{
mkdir($thumb_path,0777,TRUE);
}


$this->load->library('upload');



$config['upload_path'] = './system/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2048'; //2 meg



$data['errors']=array();
$data['uploaded_files']=array();
$this->load->model('Process_image');
foreach($_FILES as $key => $value)


{
$this->upload->initialize($config);
if ( ! $this->upload->do_upload($key))




{
=>$this->upload->display_errors());




}
else
{


$this->Process_image->process_pic($this->upload->data());
$data['uploaded_files'][] = $this->upload->data();

}

}


$data['message'] = (count($data['errors']) > 0)?implode('',$data['errors']):'All files were uploaded successfully.';


$this->load->view('propreg/f_propreg3_multifileupload_v1', $data); //Upload Form


}//end picupload
}//end controller
?>
#2

[eluser]tim1965[/eluser]
My View

<?php echo form_open_multipart('c_f_propreg3_multifileupload_v1/picupload', array('id' => 'c_f_propreg3_multifileupload_v1/picupload')); ?>


<?php echo $message; ?>

<?php echo $uploaded_files; ?>



<fieldset>

<p>

<label for="main_photo_description" class="left">Main photo description :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_1" type="file" id="userfile_1" size="32" /&gt;
</p>

<p>
<label for="Photo description 2">Photo description 2 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_2" type="file" id="usefile_2" size="32" /&gt;
</p>
<p>
<label for="Photo description 3">Photo description 3 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_3" type="file" id="userfile_3" size="32" /&gt;
</p>
<p>
<label for="Photo description 4">Photo description 4 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_4" type="file" id="userfile_4" size="32" /&gt;
</p>

<p>
<label for="Photo description 5">Photo description 5 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_5" type="file" id="userfile_5" size="32" /&gt;
</p>

<p>
<label for="Photo description 6">Photo description 6 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_6" type="file" id="userfile_6" size="32" /&gt;
</p>

<p>
<label for="Photo description 7">Photo description 7 :</label>
&lt;input name="photo_desc[]" type="text" id="photo_desc[]" /&gt; Select Photo
&lt;input name="userfile_7" type="file" id="userfile_7" size="32" /&gt;
</p>

<p>
</fieldset>
&lt;input type="submit" value="Upload Photo´s" /&gt;

&lt;?php echo form_close(); ?&gt;

Any help appreciated
#3

[eluser]tim1965[/eluser]
Bumped coz i need some help

Ok let me ask the first question in a different way. Does display_errors only cater for one file being uploaded at a time. Ergo there is no way to link the errors if you upload more than one file at a time.
Has anybody tried my approach of trying to upload all the files at the same time and if so how did they handle the error reporting.
Many thanks again.
#4

[eluser]Dam1an[/eluser]
Is there really any need to bump a thread just 4 hours after you created the thread?
Half the active CI population won't have even been online yet

(And I've not tried your approach, so can't really comment)
#5

[eluser]tim1965[/eluser]
Apologies if i jumped too quickly.




Theme © iAndrew 2016 - Forum software by © MyBB