3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Multiupload extends MY_Controller { /* ----------------------------------------------------------------------------------- * It's actualy not my own source, but I just want to share & bookmark it here ;) * * Thanks to Anggy Trisnawan * Url: http://anggytrisnawan.com/blog/2012/07/21/upload-multiple-file-codeigniter * ----------------------------------------------------------------------------------- */ function __construct() { parent::__construct(); // load the libraries at first $this->load->library('image_lib'); $this->load->helper(array('form', 'url')); } // front view function index() { /* ----------------------------------------------------------------------------------- * It's what you need for the 'upload' view * ----------------------------------------------------------------------------------- * <?php echo form_open_multipart('upload/do_upload');?> * * <!-- make sure you give an array (userfile[]) to the "name" attribute and have attribute "multiple" on it --> * <?php echo form_input( array( 'name'=>'userfile[]', 'multiple'=>true ) ); ?><br /> * * <!-- just, another submit button --> * <?php echo form_submit('submit', 'Upload'); ?> * * <!-- well, close the form --> * <?php echo form_close();?> * ----------------------------------------------------------------------------------- */ $data['multiupload'] = "multiupload"; // Controller $data['view'] = "form_multiupload"; // View $data['module'] = "multiupload"; // Controller $data['error'] = ' '; echo Modules::run('template/staff', $data); } // Upload & Resize in action function do_upload() { $upload_conf = array( 'upload_path' => realpath('assets/doc/img/real/'), 'allowed_types' => 'gif|jpg|png|JPEG|JPG', 'max_size' => '30000', 'encrypt_name' => TRUE, 'overwrite' => TRUE, ); $this->load->library('upload', $upload_conf); //$this->upload->initialize($upload_conf); foreach ($_FILES['userfile'] as $key => $val) { $i = 1; foreach ($val as $v) { $field_name = "file_" . $i; $_FILES[$field_name][$key] = $v; $i++; } } // Unset the useless one ;) unset($_FILES['userfile']); foreach ($_FILES as $field_name => $file) { if (!$this->upload->do_upload($field_name)) { echo $this->image_lib->display_errors(); } else { $upload_data = $this->upload->data(); $ori = $upload_data['file_name']; $mr = $upload_data['file_path'] . $ori; $this->watermarking($mr); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/full/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 0; $config['height'] = 0; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //this is the larger image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/medium/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 342; $config['height'] = 342; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //small image $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/small/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 152; $config['height'] = 152; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); //cropped thumbnail $config['image_library'] = 'gd2'; $config['source_image'] = $upload_data['full_path']; $config['new_image'] = 'assets/doc/img/thumbnails/' . $upload_data['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 62; $config['height'] = 62; $this->image_lib->initialize($config); $this->image_lib->resize(); $this->image_lib->clear(); // do it! if (!$this->image_lib->resize()) { // if got fail. //$error['resize'][] = $this->image_lib->display_errors(); echo $this->image_lib->display_errors(); } else { // otherwise, put each upload data to an array. $success[] = $upload_data; } } } // see what we get if (count($error > 0)) { $data['error'] = $error; } else { $data['success'] = $upload_data; } $data['multiupload'] = "multiupload"; // Controller $data['view'] = "index_multiupload"; // View $data['module'] = "multiupload"; // Controller $data['error'] = ' '; dump($this->upload->data()); echo Modules::run('template/staff', $data); } } /* End of File: multiupload.php */
Output for git.master, git.master_jit, rfc.property-hooks
No direct script access allowed

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.02 ms | 401 KiB | 8 Q