Codeigniter上传问题:file_name不能正常工作

时间:2015-08-16 10:55:06

标签: php codeigniter image-uploading

我使用codeigniter并在上传文件中我遇到了问题。 file_name是重复产生的。

我的模型:(db_category)

public function do_upload($route = "./category-pic/") {
    $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path'   => $route,
            'encrypt_name'  => 'TRUE',
            'max_size'      =>  3000
    );
    $this->load->library("upload", $config);
}

我的控制器:

$this->db_category->do_upload("./product-pic/");
foreach ($_FILES as $key => $value) {
    $this->upload->do_upload($key);
    $data_name = $this->upload->data();
    $k++;
    if (is_uploaded_file($_FILES['file'.$k]['tmp_name'])) {
        // This is produced Repetitiously sometimes for different pictures.
        echo $data_name['file_name']. " ****** ";
    }
}

我的观点简单明了,如:

echo '<input type="file" name="file1" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file4" id="my_uploader" style="width: 210px;" />';

注意:所有图片都有自己的名字上传,但问题出在$data_name['file_name']

有什么问题?感谢。

1 个答案:

答案 0 :(得分:0)

最后我找到了答案!从视图部分来看,这是一个错误的错误。

输入文件未按顺序写入。例如,它是这样的:

echo '<input type="file" name="file5" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';

我不知道为什么这会导致问题。

相关问题