Welcome Guest, Not a member yet? Register   Sign In
Is it a good idea to overwrite Super Global Variables ??
#1

In my opinion, we should discourage, happy to understand what best practice should be ?

Example, where $_FILES is overwritten as

 
PHP Code:
$filesCount count($_FILES['files']['name']);
 
       for($i 0$i $filesCount$i++){
 
           $_FILES['file']['name'    $_FILES['files']['name'][$i];
 
           $_FILES['file']['type'    $_FILES['files']['type'][$i];
 
           $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
 
           $_FILES['file']['error'    $_FILES['files']['error'][$i];
 
           $_FILES['file']['size'    $_FILES['files']['size'][$i];

 
           // File upload configuration
 
           $uploadPath 'uploads/files/';
 
           $config['upload_path'] = $uploadPath;
 
           $config['allowed_types'] = 'jpg|jpeg|png|gif';

 
           // Load and initialize upload library
 
           $this->load->library('upload'$config);
 
           $this->upload->initialize($config);

 
           // Upload file to server
 
           if($this->upload->do_upload('file')){
 
               // Uploaded file data
 
               $fileData $this->upload->data();
 
               $uploadData[$i]['file_name'] = $fileData['file_name'];
 
               $uploadData[$i]['uploaded_on'] = date("Y-m-d H:i:s");
 
           }
 
       

This is commonly used code to upload multiple files .. 
If this is bad approach.. please share working code for multiple file upload without modify super globals.
Reply
#2

There must be a lot of github projects with codeigniter and multiple file uploads.

Personally, I've never needed a multiple file upload.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

(09-14-2018, 11:18 AM)oppachoriya Wrote: In my opinion, we should discourage, happy to understand what best practice should be ?

Example, where $_FILES is overwritten as

 
PHP Code:
$filesCount count($_FILES['files']['name']);
 
       for($i 0$i $filesCount$i++){
 
           $_FILES['file']['name'    $_FILES['files']['name'][$i];
 
           $_FILES['file']['type'    $_FILES['files']['type'][$i];
 
           $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
 
           $_FILES['file']['error'    $_FILES['files']['error'][$i];
 
           $_FILES['file']['size'    $_FILES['files']['size'][$i];

 
           // File upload configuration
 
           $uploadPath 'uploads/files/';
 
           $config['upload_path'] = $uploadPath;
 
           $config['allowed_types'] = 'jpg|jpeg|png|gif';

 
           // Load and initialize upload library
 
           $this->load->library('upload'$config);
 
           $this->upload->initialize($config);

 
           // Upload file to server
 
           if($this->upload->do_upload('file')){
 
               // Uploaded file data
 
               $fileData $this->upload->data();
 
               $uploadData[$i]['file_name'] = $fileData['file_name'];
 
               $uploadData[$i]['uploaded_on'] = date("Y-m-d H:i:s");
 
           }
 
       

This is commonly used code to upload multiple files .. 
If this is bad approach.. please share working code for multiple file upload without modify super globals.

$upload_dir ='upload/';
    if(isset($_FILES["sticker_image"]["name"]) && $_FILES["sticker_image"]["name"]!="")
{
$config['upload_path'] = $upload_dir; 
$config['allowed_types'] = 'png'; 
$file = time().'_'.str_replace(' ','_',$_FILES["sticker_image"]['name']);
$insert["sticker_image"] = $file;
$config['file_name'] = $file;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->do_upload('sticker_image');
}


Try this code.
Reply
#4

Here is a tutorial on it that shows how to do it without all that mess.

Codeigniter Multiple Files Upload
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB