代码之家  ›  专栏  ›  技术社区  ›  rabidmachine9

将照片的路径存储在编码器点火器中

  •  0
  • rabidmachine9  · 技术社区  · 15 年前

    我按照本教程学习了如何在CodeIgniter文件夹中上载照片: http://codeigniter.com/user_guide/libraries/file_uploading.html

    有人能告诉我如何存储我刚上传到数据库中的照片的路径吗? 比如说叫人给桌子打电话 photo_paths 提前谢谢

    2 回复  |  直到 15 年前
        1
  •  1
  •   Bella    15 年前

    这假设您有一个图像表。

    按如下方式配置文件上载:

     $config['upload_path'] = './images/';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size']    = '1000000';
     $config['overwrite'] = TRUE;
     $config['remove_spaces'] = TRUE;
     $config['encrypt_name'] = FALSE;
    
     $this->load->library('upload', $config);
    

    上传成功后,将文件信息插入数据库。

    $insert_data = array(
    'id_fk' => $this->input->post('page_id'),
    'imgfilename' => $upload_info['file_name'],
    'imgfilepath' => $upload_info['file_path']
    );
    $this->db->insert('images', $insert_data);
    

    成功上传后,使用以下方法从文件上传程序类中检索$upload信息:

    $upload_info = $this->upload->data();
    

    如果您想查看返回的内容:

    echo var_dump($upload_info);
    
        2
  •  0
  •   Matthew    15 年前

    对于我来说,由于我上传的大多数图像都是相同的(例如,产品图像),我可能只是将文件名(例如,productshot1.jpg)存储在数据库中,因为我知道文件名在哪里(例如,我可能将所有产品图像保存在“/images/products/”)。这样,如果你以后需要改变,就不那么困难了。

    推荐文章