簡體   English   中英

不使用數組上傳codeigniter文件

[英]codeigniter file uploading without using array

我已經使用了codeigniter文件上傳,單個和多個。 但是如果文件名不在數組中,則如何上傳文件。 例如:-如果form1具有file1,file2和file3文件輸入,並且用戶僅提供file1和file3。 那么如何識別file2是否未給出。 如果我使用數組格式,則不可能找到給出的特定字段,而沒有給出。

我已經嘗試過基於數組的上傳,但是任何丟失的文件都會給我一個錯誤索引的數組。 我需要有一個適當的$_POST ,其中明確給出了未選擇的表單成員。

它將僅發布具有值的$_FILES

的HTML

<input type="file" name="mass_consume_upload[]" />
<input type="file" name="mass_consume_upload[]" />
<input type="file" name="mass_consume_upload[]" />

PHP(Codeigniter)

        $this->load->library('upload');

        $tempfiles = $_FILES;
        //print_r($tempfiles);
        foreach ($tempfiles as $files) {
            $_FILES['mass_consume_upload'] = $files;

            $this->upload->initialize(array(
                'upload_path' => $path,
                'allowed_types' => 'pdf',
                'overwrite' => FALSE
            ));
            if (!$this->upload->do_upload('mass_consume_upload')) {
                $uploadArr['error'][] = array(
                    'filename' => $_FILES['mass_consume_upload']['name'],
                    'msg' => $this->upload->display_errors('', '')
                );
            } else {
                $uploadArr['success'][] = array('filename' => $_FILES['mass_consume_upload']['name']);
            }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM