...

View Full Version : Resolved build array with only used inputs



durangod
10-16-2012, 09:31 AM
Hi i am building a multiple pic uploader and i have some questions.

i have 9 file inputs, well i have one but i put it in a while loop so it does it 9 times.

But if someone only uses 1 of the inputs it still builds an array of 9, 1 has data and the other 8 have zip.

How do i get just the one input in the array, and only load what they use?

here is the input while loop

there is a table started up here




<?php
$c=1;
while($c <= 9)
{
?>

<tr align="center">
<td colspan="4">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" size="20" class="inputf" />

<?=$c;?>)&nbsp;<input type="file" name="uimages[]" id="uimages" size="20" class="inputf" />

<input type="text" value="Title" name="title" />

</td>
</tr>


<?php
$c++;
}//end while
?>

and then table closes here when its done looping and also the submit is down here as well.





And then my other question is how do i grab each one on the php side, i like this format because it processes one at a time instead of all at once. So it saves me the hassle of my max upload issue.


here is my foreach on the php side.

when this was a single upload process it used the word "file" as the name in the input.
i changed it in the input form to the array uimages[]
so when you look at this alot of it is original, i just changed the name
from file to uimages and added the foreach loop, which im sure is wrong.

I think i have to address each one as [key] right?




if ($_REQUEST['ADD'])
{

foreach($_FILES["uimages"]["name"] as $key => $value)
{


$item = new GalleryItem();
count($_FILES['uimages']['type']);

$aType = split("/",$_FILES['uimages']['type']);


$data = array( 'Gallery_ID' => $Gallery_ID,
'filepath' => $_FILES["uimages"]["tmp_name"],
'Type' => ucfirst(array_shift($aType)),
'SubType' => array_shift($aType),
'title' => $title,
);

//echo "<pre>";
//print_r($data);


$result = $item->Init((object)$data);

$result = $item->Save();


}//close foreach

}//close if add

durangod
10-16-2012, 10:22 AM
i think i might have the key deal done, here is the new php for that part





foreach($_FILES["uimages"]["name"] as $key => $value)
{


$item = new GalleryItem();
count($_FILES['uimages']['type']);

$aType = split("/",$_FILES['uimages']['type'][$key]);


$data = array( 'Gallery_ID' => $Gallery_ID,
'filepath' => $_FILES["uimages"]["tmp_name"][$key],
'Type' => ucfirst(array_shift($aType)),
'SubType' => array_shift($aType),
'title' => $title,
);

//echo "<pre>";
//print_r($data);


$result = $item->Init((object)$data);

$result = $item->Save();


}//close foreach

}//close if add





what im trying to do now is the input title for each image is a seperate input and im trying get that array done and also combine that title array with the files array if i can so i dont have to do two foreach loops


UPDATE i got the title figured out it was in the post so i just grabbed it in the foreach loop by $key along with the other data.

I guess i use the error part of the $_FILES array and if 0 its ok, if not or its 4 then its not used correct?

durangod
10-16-2012, 10:46 AM
HORRAY! i got it working ok resolved using the error part of the files array worked, cool beans... resolved



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum