io sono un novizio Codeigniter e sto cercando di ottenere il nome del file di un'immagine caricata in modo che io possa salvarlo nel database. Ho due modelli, homemodel si occupa del mio database e l'image_upload_model si occupa del caricamento delle immagini. Tutto funziona bene, tranne io non so come per pubblicare il nome del file immagine al databaseCodeigniter: come ottenere un nome file di un file
image_upload_model.php
<?php
class Image_upload_model extends CI_Model {
var $image_path;
//constructor containing the image path
function Image_upload_model() {
$this->image_path = realpath(APPPATH.'../assets/img');
}
//uploading the file
function do_upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->image_path
);
$this->load->library('upload',$config);
$this->upload->do_upload();
}
}
?>
homemodel.php
<?php
class homeModel extends CI_Model {
//inserting into the table tenants
function addTenants() {
$this->load->model('Image_upload_model');
$data = array(
'Fname' => $this->input->post('Fname'),
'Lname' => $this->input->post('Lname'),
'contact' => $this->input->post('contact'),
'email' => $this->input->post('email'),
'location' => $this->input->post('location'),
'img_url' => " "//the filename of the image should go here
);
$this->db->insert('tenants', $data);
}
}
?>
Il controller
homecontroller.php
<?php
class HomeController extends CI_Controller {
public function index() {
$this->load->helper('form');
$this->load->helper('html');
$this->load->model('homemodel');
$this->load->model('Image_upload_model');
if ($this->input->post('submit') == 'Submit') {
$this->homemodel->addTenants();
echo 'inserted';
$this->Image_upload_model->do_upload();
echo 'image uploaded';
}
$this->load->view('index.php');
}
}
?>
qualsiasi aiuto è apprezzato, grazie!
Hai controllato [File di classe Updloading] (http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html)? Gestisce praticamente il caricamento dei file. –