图像上传与codeigniter [英] image uploading with codeigniter

查看:143
本文介绍了图像上传与codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图上传一个图像并保存图像的完整路径在我的图像表,但我不知道如何获得完整的路径它从 $ this-> upload->数据) array这是我的代码如下。

Am trying to upload an image and save the images full path in my images table but i dont know how to get the full path it out of the $this->upload->data() array this is my code below.

//assigns the user's sessioned id to the variable $user_id

$user_id = $this->session->userdata('user_id');

//sets rules for the image that is being uploaded
$config['overwrite'] = FALSE; //does not overwrite any image adds +1 instead
$config['encrypt_name'] = FALSE; //encrypts the images name
$config['remove_spaces'] = TRUE; //removes spaces from the images name
$config['file_name'] = $user_id."_0.jpg";/*gives the image a new name combination of the user's id and a number*/
$config['upload_path'] = './uploads'; // the uploaded images path
$config['allowed_types'] = 'jpg|png';/*types of image extentions allowed to be uploaded*/
$config['max_size'] = '2048';// maximum file size that can be uploaded (2MB)

if ( ! is_dir($config['upload_path']) ) /* this checks to see if the file path is wrong or does not exist.*/
    die("THE UPLOAD DIRECTORY DOES NOT EXIST"); // error for invalid file path

$this->load->library('upload',$config); /* this loads codeigniters file upload library*/
//this checks for errors incase the image upload breaks a set rule.
if (! $this->upload->do_upload() ) {
    echo "UPLOAD ERROR ! ".$this->upload->display_errors(); //image error
}
else {
    // success message to show that the image was successfuly uploaded.
    echo "THE IMAGE HAS BEEN UPLOADED : "; var_dump($this->upload->data() );
}


推荐答案

以存储变量中的数组 $ this-> upload-> data();

All I needed to do was to store the array $this->upload->data(); in a variable for example

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

并从 $ image_info 访问图片属性。

$image_info['full_path'];
$image_info['file_name'];

这篇关于图像上传与codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆