【问题标题】:Codeigniter upload issue: file_name doesn't work fineCodeigniter 上传问题:file_name 无法正常工作
【发布时间】:2015-08-16 10:55:05
【问题描述】:

我使用 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']

有什么问题?谢谢。

【问题讨论】:

    标签: php codeigniter image-uploading


    【解决方案1】:

    而不是

    $data_name['file_name'];
    

    使用

    $_FILES['file'.$k]['name'];
    

    【讨论】:

    • 非常感谢。但有一个问题。 Codeigniter 将图片名称更改为'encrypt_name' =&gt; 'TRUE',但您的 php 代码没有,我以原始名称插入数据库。
    • 你能告诉我 $data_name 变量吗? echo "
      ".$print_r($data_name)."
      ";
    • 你看,第一个之后,三个是一样的!但它们上传得很好。
    • 请告诉我更新数据库的功能。
    • 一些你需要如何刷新 $data_name 变量。
    【解决方案2】:

    终于找到答案了!从视图部分来看这是一个严重的错误。

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

    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;" />';
    

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

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 2014-06-25
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多