текст не работающего запроса в POST
var str=['--1b\r\n',
'Content-Disposition: form-data; name="text_field"\r\n',
'\r\n',
'text in field.\r\n',
'--1b\r\n',
'Content-Disposition: form-data; name="files"\r\n',
'Content-Type: multipart/mixed; boundary=2b\r\n',
'\r\n',
'--2b\r\n',
'Content-Disposition: file; filename="file1.txt"\r\n',
'Content-Type: text/plain\r\n',
'\r\n',
'... contents of file1.txt ...\r\n',
'--2b\r\n',
'Content-Disposition: file; filename="file2.txt"\r\n',
'Content-Type: text/plain\r\n',
'\r\n',
'...contents of file2.txt...\r\n',
'--2b--\r\n',
'--1b--'].join('');
при общих заголовках:
oHeader['Content-Type']='multipart/form-data; boundary=1b';
oHeader["Content-Length"]= str.length;
PHP скрипт с кодом:
echo '<pre>';
echo 'Post'; print_r($_POST,false);
echo 'Files'; print_r($_FILES,false);
echo '</pre>';
выдаёт мне не корректный ответ на запрос выше:
Код:
|
PostArray
(
[text_field] => text in field.
[files] => --2b
Content-Disposition: file; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--2b
Content-Disposition: file; filename="file2.txt"
Content-Type: text/plain
...contents of file2.txt...
--2b--
)
FilesArray
(
) |
тогда как я ожидал видеть files внтри массива обозначенного FilesArray.
Делал я согласно статьям
http://phpclub.ru/detail/article/http_request
(про использование Content-Disposition: form-data; без Content-Type: multipart/mixed; то что получилось)
и
http://www.w3.org/TR/REC-html40/inte...m-content-type.
(ссылка с первой статьи, как раз с Content-Type: multipart/mixed; то что не получилось)
Получился запрос только с Content-Disposition: form-data; :
var str=['--1b\r\n',
'Content-Disposition: form-data; name="text_field"\r\n',
'\r\n',
'text in field.\r\n',
'--1b\r\n',
'Content-Disposition: form-data; name="file1"; filename="file1.txt"\r\n',
'Content-Type: application/octet-stream\r\n',
'Content-Transfer-Encoding: binary\r\n',
'\r\n',
'... contents of file1.txt ...\r\n',
'--1b\r\n',
'Content-Disposition: form-data; name="file2"; filename="file2.txt"\r\n',
'Content-Type: application/octet-stream\r\n',
'Content-Transfer-Encoding: binary\r\n',
'\r\n',
'...contents of file2.txt...\r\n',
'--1b--'].join('');
всё нормально, получаю нормальный ответ:
Код:
|
PostArray
(
[text_field] => text in field.
)
FilesArray
(
[file1] => Array
(
[name] => file1.txt
[type] => application/octet-stream
[tmp_name] => Z:\tmp\phpDD.tmp
[error] => 0
[size] => 29
)
[file2] => Array
(
[name] => file2.txt
[type] => application/octet-stream
[tmp_name] => Z:\tmp\phpDE.tmp
[error] => 0
[size] => 27
)
) |
Конечно, можно обходиться последним вышеприведённым работающим способом,
но меня заманивает возможность с использованием Content-Type: multipart/mixed;
А заманивает тем, что когда-то давно я получал несколько иную структуру массива $_FILES,
так например, я тогда бегал по массиву и копировал временные файлы в другую директорию:
for($i=0; $i<count($_FILES["file"]["name"]); $i++)
{
copy($_FILES["file"]["tmp_name"][$i],basename($_FILES["file"]["name"][$i]));
};
отсюда видно что $_FILES["file"]["tmp_name"] - это не одно значение, а массив из строковых значений,
а теперь из одного значения, т.е. другая структура, вот и возникло подозрение, что прежняя структура
получалась с помощью Content-Type: multipart/mixed;,
если нет, то каким запросом достигается прежняя структура?