如何在PHP中获取值形式数组

约翰王子

我想在Codeigniter中上传多个图像,然后将上传的图像文件名插入名为gallery的数据库表中。

多个图像已成功上传,但我无法捕获已上传图像的文件名。下面是我的功能

public function products() { 
    $this->load->library('upload');
    $uploadData = array();
    //$fileData = array();
    $files = $_FILES;
    $count = count($_FILES['userfile']['name']);

    for($i=0; $i<$count; $i++) {
        $_FILES['userfile']['name']= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']= $files['userfile']['size'][$i];  

        $imagePath = realpath(APPPATH . '../images/website/gallery');           
        $config['upload_path'] = $imagePath;
        $config['allowed_types'] = 'gif|jpg|png';
        $config['file_name'] = date('Ymd_his_').rand(10,99).rand(10,99).rand(10,99);
        $this->upload->initialize($config);

        if($this->upload->do_upload()) {
            $fileData = $this->upload->data();
            echo "<pre>"; var_dump($fileData); echo "</pre>";
            //inset code will be here               
        } else {
            echo strip_tags($this->upload->display_errors());
        }
    }
}
echo "<pre>"; var_dump($fileData); echo "</pre>"; result is below 

array(14) {
  ["file_name"]=>
  string(26) "20170116_101759_563596.jpg"
  ["file_type"]=>
  string(10) "image/jpeg"
  ["file_path"]=>
  string(43) "H:/Xampp/htdocs/cms/images/website/gallery/"
  ["full_path"]=>
  string(69) "H:/Xampp/htdocs/cms/images/website/gallery/20170116_101759_563596.jpg"
  ["raw_name"]=>
  string(22) "20170116_101759_563596"
  ["orig_name"]=>
  string(26) "20170116_101759_563596.jpg"
  ["client_name"]=>
  string(10) "vision.jpg"
  ["file_ext"]=>
  string(4) ".jpg"
  ["file_size"]=>
  float(28.32)
  ["is_image"]=>
  bool(true)
  ["image_width"]=>
  int(383)
  ["image_height"]=>
  int(291)
  ["image_type"]=>
  string(4) "jpeg"
  ["image_size_str"]=>
  string(24) "width="383" height="291""
}
array(14) {
  ["file_name"]=>
  string(26) "20170116_101759_165983.jpg"
  ["file_type"]=>
  string(10) "image/jpeg"
  ["file_path"]=>
  string(43) "H:/Xampp/htdocs/cms/images/website/gallery/"
  ["full_path"]=>
  string(69) "H:/Xampp/htdocs/cms/images/website/gallery/20170116_101759_165983.jpg"
  ["raw_name"]=>
  string(22) "20170116_101759_165983"
  ["orig_name"]=>
  string(26) "20170116_101759_165983.jpg"
  ["client_name"]=>
  string(22) "Vision-and-Mission.jpg"
  ["file_ext"]=>
  string(4) ".jpg"
  ["file_size"]=>
  float(1950.72)
  ["is_image"]=>
  bool(true)
  ["image_width"]=>
  int(2121)
  ["image_height"]=>
  int(1414)
  ["image_type"]=>
  string(4) "jpeg"
  ["image_size_str"]=>
  string(26) "width="2121" height="1414""
}

我想捕获[“ file_name”] =>值并动态插入数据库中。每个图像文件将一一插入。如果上传了五个或更多图像,则该数字图像file_name将插入db中。下面是我的示例表。

**id | file_name** 
1  | 20170116_101759_165983.jpg
2  | 20170116_101759_165984.jpg
3  | 20170116_101759_165985.jpg

我已经尝试了许多教程,但是失败了。

谢谢

塔里克

简单地从$ fileData数组中获取上传的文件名

    if($this->upload->do_upload()){
                $fileData = $this->upload->data();

             $filename = $fileData['file_name'];
  ///insert this $filename value in db

            }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在 PHP 对象数组中获取值

来自分类Dev

如何使用php从数组中获取值

来自分类Dev

在PHP中从数组获取值

来自分类Dev

从PHP数组中获取值

来自分类Dev

如何在PHP中使用数组获取值元素[@attributes]

来自分类Dev

如何从数组中获取值

来自分类Dev

如何从数组中获取值?

来自分类Dev

如何从PHP中的数组的选择选项中获取值?

来自分类Dev

如何在systemverilog中获取值数组作为plusargs?

来自分类Dev

如何在角度数组中获取值?

来自分类Dev

如何在systemverilog中获取值数组作为plusargs?

来自分类Dev

如何在以下结构的json数组中获取值

来自分类Dev

我如何在这个多维数组中获取值

来自分类Dev

如何从PHP中的嵌套数组获取值

来自分类Dev

PHP:如何从多个数组中的键获取值

来自分类Dev

如何在php中通过标记名获取值?

来自分类Dev

如何在php中通过ItemID获取值ItemSum?

来自分类Dev

PHP,Smarty,如何从多维数组获取值

来自分类Dev

PHP在多维数组中获取值

来自分类Dev

PHP仅从数组中获取值

来自分类Dev

从PHP中的数组获取值的索引

来自分类Dev

从PHP中的Json数组获取值

来自分类Dev

从PHP中的Json数组获取值

来自分类Dev

PHP仅从数组中获取值

来自分类Dev

PHP - 在循环中从数组中获取值

来自分类Dev

循环从 php 数组中获取值

来自分类Dev

使用 PHP 从 JSON 数组中获取值

来自分类Dev

从数组中获取值 PHP - 非法偏移

来自分类Dev

PHP 从 JSON 数组中获取值