var_dump($_FILES)
gives the following:
array
'test1' =>
array
'name' =>
array
'f' => string 'ntuser.dat.LOG' (length=14)
'type' =>
array
'f' => string 'application/octet-stream' (length=24)
'tmp_name' =>
array
'f' => string 'D:\wamp\tmp\php22开发者_如何学运维3.tmp' (length=22)
'error' =>
array
'f' => int 0
'size' =>
array
'f' => int 0
Why is http designed this way?How can I process the array efficiently(sometimes means no looping?) so I can get the file by $_FILES['test1']['f']
?
I guess input
fields with type file
are not meant to be used with array like names.
Use
<input type="file" name="test1_f" />
instead and access with $_FILES['test1_f']
.
Otherwise you cannot access the single attributes of the file without looping.
Maybe you can show us how you create the input elements and how you want to process the $_FILES
array in order to provide a better solution.
Update:
I have to redraw my statement partially. As described here, PHP supports HTML array feature also for files. But the point with this is, that the files on the server side should be processed as a whole.
They also provide a nice example how too deal with, maybe it helps you:
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
}
}
If you want to have access to a single file, then you just use the wrong approach.
Seems to be pretty straightforward:
$filepath = $_FILES["test1"]["tmp_name"]["f"];
精彩评论