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
?>


Messages In This Thread
Yet another cry for help on file uploads - by El Forum - 05-19-2009, 02:42 AM
Yet another cry for help on file uploads - by El Forum - 05-19-2009, 02:43 AM
Yet another cry for help on file uploads - by El Forum - 05-19-2009, 06:56 AM
Yet another cry for help on file uploads - by El Forum - 05-19-2009, 07:03 AM
Yet another cry for help on file uploads - by El Forum - 05-19-2009, 07:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB