Originally posted by ppmax:
This is a really stoopid question but I'm having a mjor brain lock right now.
I have an array ($files) that contains the set of file names in a particular directory. there are 14 items in this array.
I want to pass this array to another php page (filelist.php). The code for my url:
a href="bla.com/filelist.php?files=$files"
when filelist.php loads i do:
echo count($_GET[files]);
...and for some reason it's returning 1 instead of 14. also, i try to iterate thru the array and echo the filenames--but no dice.
when i mouse over the link it says:
http://www.bla.com/filelist.php?filelist=Array
what am I doing wrong?? passing arrays is just like passing any other variable right?
thx
ppmax
Nope. Passing arrays via a request variable requires you to 'pack' it first, then 'unpack' it when you load the next page. Arrays can't be described by request variables unless you manually break them down into their component form before you send the form (e.g. < input name="form[files][a]" value="filea" /><input name="form[files][b]" value="fileb" />... etc...)
The 'serialize' and 'unserialize' functions are what you need if you want a simple way or utilising GET request variables. Have a squiz on php.net for a quick tutorial.
Something like:-
[php]
$file = serialize($file);
$link = "http://www.server.com/index.php?filelist=".urlencode($file)."";
[/php]
and on the receiving page...
[php]
$file = $_REQUEST['filelist'];
$file = unserialize($file);
if (!is_array($file) || empty($file)) { die("Not valid"); }
Your code...
[/php]
Does this help?