Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Controller
- function save(){
- $data = array();
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'jpg|png';
- $this->load->library('upload', $config);
- $data['titulo'] = $this->input->post('titulo');
- $data['descripcion'] = $this->input->post('descripcion');
- if (!$this->upload->do_upload('userfile')) {
- $error = array('error' => $this->upload->display_errors());
- } else {
- $fileData = $this->upload->data(); //Se toma el nombre
- $data['userfile'] = $fileData['file_name'];
- }
- if (!$this->upload->do_upload('userfile2')) {
- $error = array('error' => $this->upload->display_errors());
- } else {
- $fileData = $this->upload->data();
- $data['userfile2'] = $fileData['file_name'];
- }
- $this->images_model->storeIMG($data);
- }
- -------------------------------------------------------------------------
- ## MODEL
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Images_model extends CI_Model{
- public function __construct()
- {
- parent::__construct();
- //Codeigniter : Write Less Do More
- }
- function storeIMG($data){
- $productos = array(
- 'titulo' => $data['titulo'],
- 'descripcion' => $data['descripcion'],
- 'userfile' => $data['upload_data']['file_name'],
- 'userfile2' => $data['upload_data']['file_name']
- );
- return $this->db->insert('Imagenes', $productos);
- }
- }
- -------------------------------------------------------------------------
- ## VIEW
- <form method="post" enctype="multipart/form-data" action="<?php base_url(); ?>Images_controller/save">
- <label for="titulo">Nombre del Producto:</label>
- <input type="text" name="titulo">
- <br><br>
- <label for="descripcion">Descripción del Producto</label><br>
- <textarea name="descripcion" rows="8" cols="80"></textarea>
- <br>
- <label for="userfile">Imagen:</label>
- <input type="file" name="userfile">
- <label for="userfile2">Segunda Imagen</label>
- <input type="file" name="userfile2" ><br><br>
- <br>
- <button type="submit">Submit</button>
- </form>
- -------------------------------------------------------------------------
- ## DB
- CREATE TABLE Imagenes (
- ID int NOT NULL AUTO_INCREMENT,
- titulo varchar(75) NOT NULL,
- descripcion int NOT NULL,
- userfile varchar(255) NOT NULL,
- userfile2 varchar(255) NOT NULL,
- PRIMARY KEY (ID)
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement