Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
- <?php
- class Sample_submit extends CI_Controller{
- protected $total;
- protected $verify;
- public function __construct() {
- parent::__construct();
- $this->load->model('Sample');
- $this->load->library('encrypt');
- }
- public function username_check()
- {
- if ($this->total != $this->verify)
- {
- $this->form_validation->set_message('username_check', 'Verification Error');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- public function index(){
- $this->total = $this->encrypt->decode($this->input->post('n1')) - $this->encrypt->decode($this->input->post('n2'));
- $this->verify = $this->input->post('verify');
- //var_dump($this->total);var_dump($this->verify); exit();
- $this->load->library('form_validation');
- $this->form_validation->set_rules('name','Name','required');
- $this->form_validation->set_rules('email','Email Address','required|valid_email');
- $this->form_validation->set_rules('desc','Description of Problem','required');
- $this->form_validation->set_rules('verify','Calculation Incorrect','callback_username_check');
- if($this->form_validation->run() == false){
- $this->load->view('sample/index', $datav);
- }else{
- if($this->input->post('web') == ""){
- $web = NULL;
- }else{
- $web = $this->input->post('web');
- }
- $data['name']= $this->input->post('name');
- $data['email']= $this->input->post('email');
- $data['desc']= $this->input->post('desc');
- $data['web']= $this->input->post('web');
- $data['user_ip']= $this->session->userdata('ip_address');;
- $data['status']= 1;
- $insert = $this->Sample->pushToVirusSubmitter($data);
- if(!$insert){
- $msg = "Write to database failed (Submitter)";
- $this->session->set_flashdata('fail',$msg);
- redirect('sample_submit/index');
- }
- $this->load->library('upload'); // Load Library
- //allowed file extension simple array
- $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";
- $this->upload->initialize(array( // takes an array of initialization options
- "upload_path" => "./uploads/virus_sample",
- "overwrite" => FALSE,
- "encrypt_name" => FALSE,
- "remove_spaces" => TRUE,
- "allowed_types" => $allowed_ext,
- "max_size" => 999999,
- "xss_clean" => FALSE
- ));
- if ($this->upload->do_multi_upload("file")) { // use same as you did in the input field
- $return = $this->upload->get_multi_upload_data();
- //store all upload information in database
- foreach($return as $d){
- $datax['file_name'] = $d['file_name'];
- $datax['file_size'] = $d['file_size'];
- $datax['file_md5'] = hash_file('md5', "./uploads/virus_sample/{$d['file_name']}") ;
- $datax['file_sha1'] = hash_file('sha1', "./uploads/virus_sample/{$d['file_name']}");
- $datax['file_sha256'] = hash_file('sha256', "./uploads/virus_sample/{$d['file_name']}");
- $datax['file_type'] = $d['file_type'];
- $datax['file_ext'] = $d['file_ext'];
- $datax['submitter'] = $insert;
- $datax['status'] = 1;
- //insert to the database
- $ins = $this->Sample->pushToVirusSample($datax);
- if($ins){
- redirect('sample_submit/thank_you/success');
- }else{
- $msg = "Write to database failed (Sample)";
- $this->session->set_flashdata('fail',$msg);
- redirect('sample_submit/index');
- }
- }
- }
- else{
- echo "<span style=\"color: red;\">" . $this->upload->display_errors() . "</span>";
- $surl = site_url('sample_submit');
- echo "<hr /><a href=\"{$surl}\">Back</a>";
- }
- }
- }
- public function thank_you(){
- $this->load->view('sample/thanks');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement