Hello All,
I am trying to upload multiple PDF files into one repeater field.
The exact situation is, if someone submits the form.
make newItem in repeater
add all the PDFs in newItem.
every thing is working without repeaters(files not getting replaced). But in repeater, only last file remains exist.Other PDFs getting replaced from the newItem field of repeater.
My code looks like-
$p2= pages->get($id);
$pdfs = new WireUpload('f_plan');
$pdfs->setMaxFiles(8);
$pdfs->setOverwrite(false);
$pdfs->setDestinationPath($upload_path);
$pdfs->setValidExtensions(array('pdf','xps'));
// execute upload and check for errors
$pdf_files = $pdfs->execute();
echo count($pdf_files); //count is working
if(!count($pdf_files))
{
$pdfs->error("Sorry, but you need to add a photo!");
return false;
}
foreach($pdf_files as $filename)
{
$p2->of(false);
$new_rep = $p2->floor_plan_rep->getNew();
$p2->save();
echo $pathname = $upload_path . $filename; //all the urls are okey
$new_rep->floor_plan = $pathname;
$p2->save();
$p2->of(true);
unlink($pathname);
}
Also it is making one extra blank repeater field inside repeater.(I know something is wrong and something is missing in my code. ).
Please help.
Thanks