Advertisement
touhid_xml

Codeigniter Multiple upload

Jul 21st, 2014
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.37 KB | None | 0 0
  1. <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
  2. <?php
  3. class Sample_submit extends CI_Controller{
  4.     protected $total;
  5.     protected $verify;
  6.     public function __construct() {
  7.         parent::__construct();
  8.         $this->load->model('Sample');
  9.         $this->load->library('encrypt');
  10.     }
  11. public function username_check()
  12.     {
  13.         if ($this->total != $this->verify)
  14.         {
  15.             $this->form_validation->set_message('username_check', 'Verification Error');
  16.             return FALSE;
  17.         }
  18.         else
  19.         {
  20.             return TRUE;
  21.         }
  22.     }
  23.     public function index(){
  24.         $this->total = $this->encrypt->decode($this->input->post('n1')) - $this->encrypt->decode($this->input->post('n2'));
  25.      $this->verify = $this->input->post('verify');
  26.      //var_dump($this->total);var_dump($this->verify); exit();
  27.         $this->load->library('form_validation');
  28.         $this->form_validation->set_rules('name','Name','required');
  29.         $this->form_validation->set_rules('email','Email Address','required|valid_email');
  30.         $this->form_validation->set_rules('desc','Description of Problem','required');
  31.         $this->form_validation->set_rules('verify','Calculation Incorrect','callback_username_check');
  32. if($this->form_validation->run() == false){
  33.   $this->load->view('sample/index', $datav);    
  34. }else{
  35.     if($this->input->post('web') == ""){
  36.      $web = NULL;  
  37.     }else{
  38.      $web =  $this->input->post('web');  
  39.     }
  40.  $data['name']= $this->input->post('name');
  41.  $data['email']= $this->input->post('email');
  42.  $data['desc']= $this->input->post('desc');
  43.  $data['web']= $this->input->post('web');
  44.  $data['user_ip']= $this->session->userdata('ip_address');;
  45.  $data['status']= 1;
  46.  $insert = $this->Sample->pushToVirusSubmitter($data);
  47.  if(!$insert){
  48.   $msg = "Write to database failed (Submitter)";
  49.   $this->session->set_flashdata('fail',$msg);
  50.   redirect('sample_submit/index');
  51.  }
  52.  
  53.  $this->load->library('upload'); // Load Library
  54.  
  55. //allowed file extension simple array
  56. $allowed_ext = "c|m|7z|ai|cs|db|gz|js|ps|py|rm|ra|3dm|3g2|3gp|8bi|aif|app|asf|asx|avi|bak|bat|bin|bmp|cab|cer|cfg|com|cpl|cpp|dbf|dbx|deb|dll|dmg|dmp|doc|csr|css|csv|cur|dat|drv|drw|dtd|dwg|dxf|efx|eps|exe|fla|flv|fnt|fon|gam|gho|gif|gpx|hqx|iff|ini|iso|jar|jpg|m3u|m4a|max|mdb|mid|mim|mov|mp3|mp4|mpa|mpg|msg|msi|nes|ori|otf|jsp|key|kml|lnk|log|pct|pdb|pdf|pif|pkg|png|pps|ppt|prf|psd|qxd|qxp|rar|rels|rom|rpm|rss|rtf|sav|sdf|sit|sql|svg|swf|sys|thm|tif|tmp|ttf|txt|uue|vb|vcd|vcf|vob|wav|wks|wma|wmv|wpd|wps|wsf|xll|xls|xml|yuv|zip|docx|indd|java|part|pptx|sitx|zipx|xlsx|pages|accdb|class|toast|plugin|gadget|tar.gz|torrent|keychain|pspimage|bat";
  57.    $this->upload->initialize(array( // takes an array of initialization options
  58.        "upload_path" => "./uploads/virus_sample",
  59.        "overwrite" => FALSE,
  60.        "encrypt_name" => FALSE,
  61.        "remove_spaces" => TRUE,
  62.        "allowed_types" => $allowed_ext,
  63.        "max_size" => 999999,
  64.        "xss_clean" => FALSE
  65.    ));
  66.    
  67.    if ($this->upload->do_multi_upload("file")) { // use same as you did in the input field
  68.        $return = $this->upload->get_multi_upload_data();
  69. //store all upload information in database
  70.        foreach($return as $d){
  71.          $datax['file_name']  = $d['file_name'];
  72.          $datax['file_size'] = $d['file_size'];
  73.          $datax['file_md5'] = hash_file('md5', "./uploads/virus_sample/{$d['file_name']}") ;
  74.          $datax['file_sha1'] =  hash_file('sha1', "./uploads/virus_sample/{$d['file_name']}");
  75.          $datax['file_sha256'] =  hash_file('sha256', "./uploads/virus_sample/{$d['file_name']}");
  76.          $datax['file_type'] = $d['file_type'];
  77.          $datax['file_ext'] = $d['file_ext'];
  78.          $datax['submitter'] = $insert;
  79.          $datax['status'] = 1;
  80. //insert to the database
  81.          $ins = $this->Sample->pushToVirusSample($datax);
  82.          if($ins){
  83.   redirect('sample_submit/thank_you/success');
  84.          }else{
  85.           $msg = "Write to database failed  (Sample)";
  86.   $this->session->set_flashdata('fail',$msg);
  87.   redirect('sample_submit/index');
  88.          }
  89.        
  90.        }      
  91.    }
  92.    else{
  93.        echo "<span style=\"color: red;\">" . $this->upload->display_errors() . "</span>";
  94.        $surl = site_url('sample_submit');
  95.        echo "<hr /><a href=\"{$surl}\">Back</a>";
  96.    }
  97.  
  98. }    
  99.     }
  100.    
  101.     public function thank_you(){
  102.     $this->load->view('sample/thanks');
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement