By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,015 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,015 IT Pros & Developers. It's quick & easy.

please help - can array hold more same key names (with differentvalues)?

P: n/a
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,

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">
<input name="userfile[]" type="file"><br>
<input name="userfile[]" type="file"><br>
<input type="submit" value="Send files">

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);

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 :(
Nov 24 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a

$postdata=array("senderid"=>"1111", "senderpass"=>"blah",
"userfile"=>array("@newclients.csv","@invoices.csv "));

echo $postdata["userfile"][0];

Nov 24 '05 #2

P: n/a
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

Nov 25 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.