Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Как можно обработать файл, если он пришел с такой формы? / 2 сообщений из 2, страница 1 из 1
01.06.2013, 08:16
    #38282221
maxterbear
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как можно обработать файл, если он пришел с такой формы?
PHP


Код: php
1.
input type=file name=item[5][parameter_value]




я пробовал так, но получаю NULL

Код: php
1.
2.
3.
4.
5.
6.
7.
foreach( $item_array as $key ) {
	
	    $parameter_id = $key['parameter_id'];
	    $parameter_value =  $key['parameter_value'];
            $f = $_FILES[$parameter_value];
	   var_dump($f);	
    }	
...
Рейтинг: 0 / 0
01.06.2013, 08:34
    #38282223
maxterbear
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как можно обработать файл, если он пришел с такой формы?
Вот нашел это, может кому-то пригодится.
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
After trying dozens of ways that are supposed to fix the wonkyness of the $_FILES array I didn't find any that could work with a input name like: userfile[christiaan][][][is][gaaf][]

So I came up with this class
<?php
/**
 * A class that takes the pain out of the $_FILES array
 * @author Christiaan Baartse <christiaan@baartse.nl>;
 */
class UploadedFiles extends ArrayObject
{
    public function current() {
        return $this->_normalize(parent::current());
    }

    public function offsetGet($offset) {
        return $this->_normalize(parent::offsetGet($offset));
    }

    protected function _normalize($entry) {
        if(isset($entry['name']) && is_array($entry['name'])) {
            $files = array();
            foreach($entry['name'] as $k => $name) {
                $files[$k] = array(
                    'name' => $name,
                    'tmp_name' => $entry['tmp_name'][$k],
                    'size' => $entry['size'][$k],
                    'type' => $entry['type'][$k],
                    'error' => $entry['error'][$k]
                );
            }
            return new self($files);
        }
        return $entry;
    }
}
?>

This allows you to access a file uploaded using the following inputtype
<input type="file" name="userfile[christiaan][][][is][gaaf][]" />
like
<?php
$files = new UploadedFiles($_FILES);
var_dump($files['userfile']['christiaan'][0][0]['is']['gaaf'][0]);
// or
foreach($files['userfile']['christiaan'][0][0]['is']['gaaf'] as $file) {
    var_dump($file);
}
?>
...
Рейтинг: 0 / 0
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Как можно обработать файл, если он пришел с такой формы? / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]