View Full Version : need advice - vars from $_POST array???

03-09-2009, 05:06 PM
Hi all,

ok, not sure on how to ask this one.....but here goes!

im writing an app that needs to read all the pdf files from a directory, then create a checklist of the items, that a user will select. it will then (eventually) create a pdf file from these pdf files and store it somewhere.

i have got the read from dir working, the issue i have at the moment is that as i dont know how many files will be found i have an unknown number of $_POST variables returned.

is there an easy way to loop through this array and take out the info?

normally i always know $_POST vars so i can just do $varname = $_POST['varname'], but this time its just something like:

[filename1] => Adhesive_Flooring_Method.pdf
[filename2] => Ceramic Tiling Method Statement.pdf
[filename3] => ceramic tiling to walls and columns Method Statement.pdf
[filename4] => Delmar_Method_Gyplyner_Flooring.pdf
[filename5] => grinding and sharpening blades - method statement.pdf

any help appreciated!

03-09-2009, 05:22 PM
Check the Example #1 at http://php.net/move_uploaded_file

03-09-2009, 05:36 PM
not sure you got what i meant. i know how to do the file manipulation bit. BUT i did get the answer i needed from that code.

foreach ($_POST as $key => $error) {
echo $_POST[$key] . "<br />\n";

im just not sure how the '$key => $error' works though. or am i even doing this right. basically i need the posted values but never knew the $_POST['varname'] part as this was all done dynamically.

03-09-2009, 05:40 PM
I think I misread your post. So you need to extract the values in your POST array and assign them to their respective simple variables?

foreach($_POST as $key=>$value){
See http://php.net/language.variables.variable

03-09-2009, 05:48 PM
you are a star mate - thanks

i guess i should have always done this rather than the masses of $varname = $_POST[varname']; eh?

really should read that manual at some point! but you know, time is precious and all that!

thanks again mate!