Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. ## Controller
  2.  
  3. function save(){
  4. $data = array();
  5.  
  6. $config['upload_path'] = './uploads/';
  7. $config['allowed_types'] = 'jpg|png';
  8.  
  9. $this->load->library('upload', $config);
  10.  
  11. $data['titulo'] = $this->input->post('titulo');
  12. $data['descripcion'] = $this->input->post('descripcion');
  13.  
  14.  
  15. if (!$this->upload->do_upload('userfile')) {
  16. $error = array('error' => $this->upload->display_errors());
  17. } else {
  18. $fileData = $this->upload->data(); //Se toma el nombre
  19. $data['userfile'] = $fileData['file_name'];
  20. }
  21.  
  22.  
  23. if (!$this->upload->do_upload('userfile2')) {
  24. $error = array('error' => $this->upload->display_errors());
  25. } else {
  26. $fileData = $this->upload->data();
  27. $data['userfile2'] = $fileData['file_name'];
  28. }
  29.  
  30. $this->images_model->storeIMG($data);
  31.  
  32. }
  33.  
  34. -------------------------------------------------------------------------
  35. ## MODEL
  36.  
  37. <?php
  38. defined('BASEPATH') OR exit('No direct script access allowed');
  39.  
  40. class Images_model extends CI_Model{
  41.  
  42. public function __construct()
  43. {
  44. parent::__construct();
  45. //Codeigniter : Write Less Do More
  46. }
  47.  
  48. function storeIMG($data){
  49. $productos = array(
  50. 'titulo' => $data['titulo'],
  51. 'descripcion' => $data['descripcion'],
  52. 'userfile' => $data['upload_data']['file_name'],
  53. 'userfile2' => $data['upload_data']['file_name']
  54. );
  55.  
  56. return $this->db->insert('Imagenes', $productos);
  57. }
  58.  
  59. }
  60.  
  61. -------------------------------------------------------------------------
  62.  
  63. ## VIEW
  64. <form method="post" enctype="multipart/form-data" action="<?php base_url(); ?>Images_controller/save">
  65.  
  66. <label for="titulo">Nombre del Producto:</label>
  67. <input type="text" name="titulo">
  68. <br><br>
  69.  
  70. <label for="descripcion">Descripción del Producto</label><br>
  71. <textarea name="descripcion" rows="8" cols="80"></textarea>
  72. <br>
  73.  
  74. <label for="userfile">Imagen:</label>
  75. <input type="file" name="userfile">
  76.  
  77. <label for="userfile2">Segunda Imagen</label>
  78. <input type="file" name="userfile2" ><br><br>
  79. <br>
  80. <button type="submit">Submit</button>
  81. </form>
  82. -------------------------------------------------------------------------
  83. ## DB
  84.  
  85. CREATE TABLE Imagenes (
  86. ID int NOT NULL AUTO_INCREMENT,
  87. titulo varchar(75) NOT NULL,
  88. descripcion int NOT NULL,
  89. userfile varchar(255) NOT NULL,
  90. userfile2 varchar(255) NOT NULL,
  91. PRIMARY KEY (ID)
  92. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement