CodeIgniter Forums
file uploading and form repopulation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: file uploading and form repopulation (/showthread.php?tid=18207)



file uploading and form repopulation - El Forum - 04-29-2009

[eluser]ramabodhi[/eluser]
Hello again,

i have been searching all over the interet for an answer to this and haven't found a clear one yet.

In my application a user can build an inventory, and on the add view, the user can add as many items as they want in one batch...

Now say they are adding 20 items to thier list, and then there is an error..

when they end back up at the form, the file path fields are empty again, and it would be annoying to have to find all 20 files again..

what is my best way at solving this problem, does it have something to do with the temp name?


file uploading and form repopulation - El Forum - 04-29-2009

[eluser]Zeeshan Rasool[/eluser]
i just need 2 things from you..

1- Did you get nothing from that fields in model or end side? check this..
i-e
Code:
if($_FILES['image1']['size'])
echo 'image available';
else
echo 'no image available';
2- Secondly, are you submitting form (like we use in yahoo attach files and come back to our email)
provide me your answer then i will give you my result.


file uploading and form repopulation - El Forum - 04-29-2009

[eluser]ramabodhi[/eluser]
question 1:

Yes I can retrieve file information with $_FILES

question 2:

i assume your asking me if the images are uploaded ona different page then redirected back to form?

no, the file upload fields are a part of the form and are uploaded on the same page with the rest of the form data

the controller handles all conditions based on if a checkbox is checked next to the file upload field


file uploading and form repopulation - El Forum - 04-29-2009

[eluser]Zeeshan Rasool[/eluser]
right you got my words. Now i think you are going right. may be some error in your back end code
same thing im using in my site to get multiple images and upload them
here is my code:
Code:
if($_FILES['image']['size'])
{            
            
$image                 = 'image';/// Name can be differnet for all images
$config['upload_path']         =  './resources/files/images';
$config['allowed_types']     = 'jpg';
$config['max_size']        = '800000';
$config['max_width']          = '1000';
$config['max_height']          = '1000';

$this->upload->initialize($config);
$this->load->library('upload', $config);

if(!$this->upload->do_upload($image))
{
$error = array('error' => $this->upload->display_errors());            
}
else
{
$data = array('upload_data' => $this->upload->data());
$file_path =$data['upload_data']['file_name'];
}
}
Above code is used to get image and upload it, the last line
$file_path =$data['upload_data']['file_name'];
is for getting uploaded file name so that we can store it in db.

try this and then confirm
keep going....


file uploading and form repopulation - El Forum - 04-29-2009

[eluser]ramabodhi[/eluser]
yes i can get the file names and store them in an array (my code is very close to yours except it is wrapped in a for loop and everything ends in _$i or [$i] depending on where im sending the data)

so in each iteration im doing
Code:
$file_path[$i] = $_FILES['userfile_'.$i]['name'];

is this eventually leading to repopulating the image location on the users computer in the form?


file uploading and form repopulation - El Forum - 04-29-2009

[eluser]Zeeshan Rasool[/eluser]
where as i am understanding, you can use some type of link(icon) near these fields so that when you upload a image then it shows near field when you click on it it shows the uploaded image. Also you can use another link to delete the image. The uploaded image path also can be shown in fields. But repopulation...!!! i have no idea yet