我正在尝试将图像路径与图像名称一起保存在数据库中。 90%我成功但只有我面临的问题是图像名称没有保存,例如在我的profile_pic字段中数据库上传/大/只有这么多保存我希望图像名称后试用斜线像上传/大/ this.jpg我无法弄清楚我的错误
//控制器
// function to upload images
function upload()
{
$session_data = $this->session->userdata('sessiondata');
$user_id = $session_data['user_id'];
//post image
$img=$this->input->post("filename");
//set preferences
$config['remove_spaces']=TRUE;
$config['encrypt_name'] = TRUE; // for encrypting the name
$config['upload_path'] = LARGEPATH;
$config['allowed_types'] = 'jpg|png|gif';
$config['max_size'] = '100000000';
//load moadel ********
$this->load->model('Edit_profile');
//load upload class library
$this->load->library('upload', $config);
//$this->upload->do_upload('filename') will upload selected file to destiny folder
if (!$this->upload->do_upload('filename'))
{
// case - failure
$upload_error = array('error' => $this->upload->display_errors());
$this->load->view('edit_profile', $upload_error);
}
else
{
// case - success
//callback returns an array of data related to the uploaded file like the file name, path, size etc
$upload_data = $this->upload->data();
//return $upload_data;
print_r($this->upload->data());
// call to model function *********
//$data['images'] = $this->Edit_profile->upload_image();
$data['images'] = $this->Edit_profile->insert_new_post($img);
$data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
$this->load->view('edit_profile', $data);
}
}
//我的模特
var $file_path;
var $file_path_url;
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->file_path = realpath(APPPATH . '../upload/large');
$this->file_path_url = base_url().'upload/large/';
//$this->is_login();
//$this->load->helper(array('form', 'url'));
}
public function upload_image()
{
$files = scandir($this->file_path);
$files = array_diff($files, array('.', '..', 'thumbs'));
$images = array();
foreach ($files as $file){
$images [] = array(
'url' => $this->file_path_url . $file,
'thumb_url' => $this->file_path_url . 'thumbs/' .$file
);
}
return $images;
}
function insert_new_post($img)
{
$session_data = $this->session->userdata('sessiondata');
$user_id = $session_data['user_id'];
$filePath = ltrim(LARGEPATH.$img['file_name'],'.');
print_r(LARGEPATH);
$query = "UPDATE `tbl_usrs` set profile_picture='".$filePath."' where user_id='".$user_id."'";
// $this->db->query($query,array($img));
$arg=array ($img);
if($this->db->query($query,$arg)==true)
{
return true; // if added to database
}else {
return false;
}
}
答案 0 :(得分:0)
尝试改变,
$filePath = ltrim(LARGEPATH.$img['file_name'],'.');
到
$filePath = ltrim(LARGEPATH.$img['file_name']);
答案 1 :(得分:0)
这是因为你需要ComboBox1.ForeColor = Color.Gray
而不是帖子字段。
upload_data['file_name']