Ads 468x60px

Pages

2010年4月13日 星期二

[PHP] upload file 的同時,存取其他的 parameters

幾天前,被問到 html form 在 upload file 的同時,如何存取其他的參數?太久沒寫 code ,一時也無法確定,所以寫了個測試程式。結果是可以用 $_POST 拿到。

[upload_form.html]
------
....

form action="http://192.168.0.1:80/ws/uploadFile" enctype="multipart/form-data" method="post"
input name="t" type="hidden" value="1271143058" 
input name="expire" type="hidden" value="1271143063" 
input name="routerAccessKeyId" type="hidden" value="05f6adb19e46f06ef0515f24e2dc586e" 
input name="sig" type="hidden" value="e53a274015c4ab6670faa98775827c3b" 
input name="path" type="hidden" value="/usb1/muchiii/photo" 
input name="callback" type="hidden" value="_getdata_123456" 

input name="filename" type="file" 
...
...
------

[uploadFile.php]
------
var_dump($_POST);
print "\n";
var_dump($_FILES);
------

得到以下結果。
------
array(6) {
  ["t"]=>
  string(10) "1271143058"
  ["expire"]=>
  string(10) "1271143063"
  ["routerAccessKeyId"]=>
  string(32) "05f6adb19e46f06ef0515f24e2dc586e"
  ["sig"]=>
  string(32) "e53a274015c4ab6670faa98775827c3b"
  ["path"]=>
  string(19) "/usb1/muchiii/photo"
  ["callback"]=>
  string(15) "_getdata_123456"
}

array(1) {
  ["uploadedfile"]=>
  array(5) {
    ["name"]=>
    string(18) "OverallSystem1.png"
    ["type"]=>
    string(9) "image/png"
    ["tmp_name"]=>
    string(14) "/tmp/phpNbiLMY"
    ["error"]=>
    int(0)
    ["size"]=>
    int(86265)
  }
}
------