Home > Archive > PHP Programming > November 2005 > please help - can array hold more same key names (with different
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
please help - can array hold more same key names (with different
|
|
| Yandos 2005-11-24, 7:56 am |
| Hi php gurus,
I need to create an array which will contain more keys with same name,
but of different values. I have no idea how to do it. Could you please
help me?
This is what I'd like to do:
$postdata=array("senderid"=>"1111", "senderpass"=>"blah",
"userfile[]"=>"@newclients.csv", "userfile[]"=>"@invoices.csv");
But userfile[] will be stored in that array only once, so I cannot use
it to feed libcurl for automated file upload :(
Is this possible to handle somehow in php? It think it is either trivial
or impossible, but i'm clueless at this point :( (If that's trivial,
please try to be patient and don't kill me for stupid question :) )
Thank you in advance,
Y.
Here's more info for those who are interested why do I need it:
The $postdata will be posted by curl to the page which looks almost
exactly like copied from PHP help:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input name="senderid" value="1111" type="hidden">
<input name="senderpass" value="blah" type="hidden">
clients:<br>
<input name="userfile[]" type="file"><br>
invoices:<br>
<input name="userfile[]" type="file"><br>
<input type="submit" value="Send files">
</form>
I initialize curl and upload (this works fine, but i need to upload both
files at once, and i cannot set them with single pass)
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $submitlink);
curl_setopt ($ch, CURLOPT_VERBOSE, 0);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_exec($ch);
Best would be if I could convince the author of that webpage to use
<input name="userfile1" type="file"><br>
<input name="userfile2" type="file"><br>
and then it would work fine, but that's what I can't :(
| |
| Yandos 2005-11-25, 7:55 am |
| On 24.11.2005 14:22, Ian B wrote:
> $postdata=array("senderid"=>"1111", "senderpass"=>"blah",
> "userfile"=>array("@newclients.csv","@invoices.csv"));
>
> echo $postdata["userfile"][0];
>
Whoa, it couldn't have been easier :)
Many thanks dear Ian :D
Y.
|
|
|
|
|