Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 12,320
» Latest member: nandhinichandran
» Forum threads: 68,560
» Forum posts: 427,553

Full Statistics

Latest Threads
CI 3.1 for Website Buildi...
Forum: Choosing CodeIgniter
4 hours ago
» Replies: 6   » Views: 3,632
Introducing TastyIgniter ...
Forum: Spotlight
5 hours ago
» Replies: 20   » Views: 22,265
Hours spent on computer?
Forum: Lounge
6 hours ago
» Replies: 32   » Views: 12,552
Do you have a hobby?
Forum: Lounge
6 hours ago
» Replies: 26   » Views: 9,523
automatic logout after in...
Forum: General Help
9 hours ago
» Replies: 0   » Views: 36
Shopping cart library not...
Forum: CodeIgniter 2.x
9 hours ago
» Replies: 1   » Views: 27
Which web hosting to use
Forum: Lounge
Yesterday, 02:58 PM
» Replies: 29   » Views: 14,632
How many pets do you own?
Forum: Lounge
Yesterday, 02:51 PM
» Replies: 10   » Views: 4,534
Which browser do you guys...
Forum: Lounge
Yesterday, 02:48 PM
» Replies: 44   » Views: 12,090
CodeIgniter 4.0.0-alpha.1...
Forum: News & Discussion
Yesterday, 01:49 PM
» Replies: 29   » Views: 17,850

 
  [Solved] Upload library issue
Posted by: f6342222 - 10-10-2018, 03:28 PM - Forum: General Help - Replies (2)

Hi. I'm having a bit of an issue with the upload library, and I would appreciate some help with it.
In essence, if I try to upload files from several inputs in the same function, I get either of two errors, depending on how I initialize the upload of any input following the first one.
If I initialize it using $this->upload->initialize($config) or $this->upload->initialize($config,TRUE), and the $config array for the previous input has something set up for the first input (ie allowed_types) while the second one shouldn't (ie if the second input shouold accept any file type), I get the following error:

Code:
You have not specified any allowed file types.

The filetype you are attempting to upload is not allowed.
And if I have more than one input (or more than one file, in an input with the multiple flag on), it shows the same error several times incrementally per input/file.

If, on the other hand, I initialize it using $this->upload->initialize($config,FALSE), assuming the previous one had $config['allowed_types'] = "jpg", the second one would only accept jpgs, and would return the following error if something else was provided, even if it should accept any file type:
Code:
The filetype you are attempting to upload is not allowed.

While what I'm making is a bit more complex than this, a barebones example would look like this.
Let's say I have two file inputs.
The first one, name="idcard", is a common file input, and should only take an image up to 10MB in filesize.
The second one, name="portfolio", has a multiple="multiple" flag set, should take any file type but up to 10MB in filesize, and would be limited to 20 files.
The controller looks like this:
Code:
function uptest() {
    $messages = array();
    if ($this->input->post('submitupload') !== NULL):
        //validation and database stuff skipped

        $this->load->library('upload');
        $timestamp = time();

        //idcard input:
        $config['allowed_types'] = "jpg|jpeg|png|gif|tiff";
        $config['max_size'] = 10240;
        mkdir(FCPATH."../media/".$timestamp."/idcard",0777,TRUE);
        $config['upload_path'] = FCPATH."../media/".$timestamp."/idcard";
        $this->upload->initialize($config);
        if ($this->upload->do_upload('idcard')):
            $messages['success_messages'][] = $_FILES['idcard']['name']." loaded correctly";
        else:
            $messages['upload_errors'][] = "idcard - ".$_FILES['idcard']['name']." - ".$this->upload->display_errors();
        endif;

        //resetting $config
        $config = array();

        //portfolio input:
        $portfolio = $_FILES['portfolio'];
        $portfolioC = count($portfolio['tmp_name']);
        if ($portfolioC <= 20):
            $config['max_size'] = 10240;
            mkdir(FCPATH."../media/".$timestamp."/portfolio",0777,TRUE);
            $config['upload_path'] = FCPATH."../media/".$timestamp."/portfolio";
            $this->upload->initialize($config,FALSE); //or $this->upload->initialize($config), which gives a different error
            for ($i=0;$i<$portfolioC;$i++):
                $_FILES['portfolio'] = array();
                $_FILES['portfolio']['tmp_name'] = $portfolio['tmp_name'][$i];
                $_FILES['portfolio']['name'] = $portfolio['name'][$i];
                $_FILES['portfolio']['type'] = $portfolio['type'][$i];
                $_FILES['portfolio']['size'] = $portfolio['size'][$i];
                $_FILES['portfolio']['error'] = $portfolio['error'][$i];
                if ($this->upload->do_upload('portfolio')):
                    $messages['success_messages'][] = $_FILES['portfolio']['name']." loaded correctly";
                else:
                    $messages['upload_errors'][] = "portfolio - ".$_FILES['portfolio']['name']." - ".$this->upload->display_errors();
                endif;
            endfor;
        else:
            $messages['error_messages'] = "You can only upload up to 20 portfolio files";
        endif;

        //rollback stuff skipped
    endif;
    $this->load->view('test/uptest',$messages);
} //function uptest
The relevant snippet of the view (views/test/uptest.php) looks like this:
Code:
<?php
    //skipping other messages, such as validation_errors
    if (isset($upload_errors)):
        foreach ($upload_errors AS $message):
            ?><div class="error"><?php echo $message?></div><?php echo "\n";
        endforeach;
    endif;
    if (isset($success_messages)):
        foreach ($success_messages AS $message):
            ?><div class="success"><?php echo $message?></div><?php echo "\n";
        endforeach;
    endif;
    echo form_open_multipart('uptest');
    ?>ID card: <input type="file" name="idcard" required="required" /><br /><?php echo "\n";
    ?>Portfolio: <input type="file" name="portfolio[]" multiple="multiple" /><br /><?php echo "\n";
    ?><input type="submit" name="submitupload" value="Submit" /><br /><?php echo "\n";
    echo form_close();
?>
So, if I have the second upload initialization (line 30 in the controller snippet) as $this->upload->initialize($config,FALSE), I get a "The filetype you are attempting to upload is not allowed" error if I have anything but images in the second input. If I have a mix of images and other file types, it would upload the images, but not the rest, for which it would return said error.
If I have it as $this->upload->initialize($config) or $this->upload->initialize($config,TRUE), I get a "You have not specified any allowed file types. The filetype you are attempting to upload is not allowed" error regardless, returning it an incremental number of times per file.

Any help would be much appreciated. Thanks in advance.


  Pros and Cons of using Plesk
Posted by: richb201 - 10-10-2018, 08:16 AM - Forum: Lounge - Replies (2)

I am considering using Plesk on AWS to help me configure my AWS Lightsail CI server/Chrome Extension application. Does anyone have any positive or negative  experiences with Plesk?


  Codeigniter 4 running error ???
Posted by: Miller - 10-10-2018, 02:34 AM - Forum: CodeIgniter 4 Support - Replies (4)

I am testing CodeIgniter 4, but I am getting this error:

Fatal error: Default value for parameters with a class type hint can only be NULL in C:\xampp\htdocs\CodeIgniter4-develop\system\Config\DotEnv.php on line 121

What am I missing?


  ajax call to On success to redirect to a different page with data from controller
Posted by: jackey - 10-10-2018, 01:56 AM - Forum: General Help - Replies (13)

hi,
I spend number of days to solve this issue.I want to echo the values in "view_print_increment_form", passed from the controller "print_increment_form". this is my source code. i'm unable to echo values. 
Can any one pls help me to solve this?


   
    function save()
  {
   
    var url;
    url = "<?php echo site_url('index.php/ClerkAE/send_increment_form')?>";

    $.ajax({
        url : url,
        type: "POST",
        data: $('#form_increment').serialize(),
        dataType: "JSON",
        success: function(data)
        {
            console.log(data);
            if(data.status)
            {
               $('#modal_increment').modal('hide');                              
               location.reload();
               window.open("<?php echo site_url('index.php/ClerkAE/print_increment_form')?>/"+data.ID , "popUpWindow","height=400,width=600,left=10,top=10,scrollbars=yes,menubar=no");
            }
            else
            {
                for (var i = 0; i < data.inputerror.length; i++) 
                {
                    $('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error'); 
                    $('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); 
                }
            }            
        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error in SAVE data');

        }
    });
  }

////////////////////////////controller/////////////////

 public function send_increment_form()
                  {
                 $data_increment_step = array(   
                 'step' => $this->input->post('salary_step'),
                 'amount' => $this->input->post('amount'),
                 'incre_tbl_id' => $this->input->post('id'),                  
                   ); 
                  
                  $this->load->model('Model_user');
$insert=$this->Model_user->model_send_increment_form(array('id' => $this->input->post('id')),$data_increment_step);
                  $this->session->set_flashdata('message', 'Your data updated Successfully.......');
                  echo json_encode(array("status" => TRUE, "ID" => $insert));         
                  
                        }
                        
            public function print_increment_form($id){            
            $this->load->model('Model_user');
            $data['user_info']=$this->Model_user->model_print_increment_form($id);      
            $this->load->view('ClerkAE/view_print_increment_form',$data);           
            }

/////////////////model///////////////

 public function model_send_increment_form($where, $data)
{       
$this->db->update('increment', array('send_form_bit'=>1), $where); 
                $this->db->insert('increment_step', $data);
                return $this->db->insert_id(); 
}
        
        
         public function model_print_increment_form($id)
         {
       
              $query = $this->db->query("SELECT i_s.*,e.emp_no, e.initials, e.last_name, c.designation, c.grade, d.dept_name,f.faculty_name "
                      . "FROM increment_step i_s, emp_pmt e, cadre c, increment i, dept d, faculty f "
                      . "WHERE i_s.id='.$id.' AND i_s.incre_tbl_id=i.id AND i.emp_no = e.emp_no AND i.cid=c.id AND d.id=e.dept_no AND d.faculty_id=f.id ");
             
               return $query->result(); 
         }

//////////////////////////////////////////////////////////////view_print_increment_form////////////////

<?php


foreach($user_info as $emp){
                
echo "<br>".$emp->emp_no."</br>";

echo "<br>".$emp->initials."".$emp->last_name." </br>";

echo  "<br>".$emp->designation."</br>";

echo  "<br>".$emp->grade."</br>";

echo  "<br>".$emp->dept_name."</br>";

echo  "<br>".$emp->faculty_name."</br>";

echo  "<br>".$emp->step."</br>";

echo  "<br>".$emp->amount."</br>";
}

?>


  Best Practice
Posted by: emilio - 10-09-2018, 08:19 PM - Forum: Libraries & Helpers - Replies (4)

Hello,

I have a doubt about using query on CI. 

Should I prefer Standard Query or is better I use Query Builder?

In other words, pro and cons about Standard Query and Query Builder.

Tanks in advance


  Update an existing app to a new version of CI
Posted by: mfox - 10-09-2018, 07:02 AM - Forum: Best Practices - Replies (2)

Good morning,

I have a couple web apps I've built with CI, and one of them uses a "-dev" version of CI (I thought I was downloading the stable release at the time, and that was well over a year ago).  So obviously, I need to update CI, or at the very least have my app use a production-ready/stable version.  How would I go about doing that?

Note that I don't have admin rights on this server, so I can't i.e. install Composer and go that route.  I've never used it before anyway (though I am definitely going to be learning, at home if nothing else, lol).

At this point, my best guess is to go on the development machine, upload the latest CI installation, and copy index.php and the "system" folder into the app's folder; obviously there may be some changes to index.php too, but those should be minimal.  everything in "application" (or just "app" in our case) is our code, so I think it would work... or am I way out in left field on that?  Thanks.


  Show logo in email inbox
Posted by: omid_student - 10-09-2018, 02:13 AM - Forum: General Help - Replies (12)

Hi
Can i show my logo in emails that we send to users?
In Google or Yahoo,in inbox,each email have logo or icon
I need add our logo too
Thanks


  Thread Modes htaccess redirects
Posted by: lamxuyen1234 - 10-08-2018, 08:57 PM - Forum: General Help - No Replies

So i tried searching the forums and a I was not able to find any help..

I am trying to redirect with htaccess but I keep getting my redirect query string appended to my url.

Here is my htaccess file.

PHP Code:
<IfModule mod_rewrite.c>
 
 RewriteEngine On
  RewriteBase 
/
 
 RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond 
%{REQUEST_FILENAME} !-d
  RewriteRule 
^(.*)$ index.php?/$[L]

 
 Redirect 301 /users/login http://example.local/login
</IfModule


How do I fixed this.. seems like the query string is getting appended to my url.


  Session table redundant records problem
Posted by: Volder - 10-07-2018, 01:49 AM - Forum: General Help - Replies (2)

Hi all,

I've been using Codeigniter for many years since 1.x versions.
The question I have is about Session library behavior, which I'm struggling to solve.

We recently upgraded PHP to 7.2 and also moved the application to CI 3.1.9 codebase.
In the 1.x and 2.x versions Session were not working properly (users were periodically logged out without a reason) and we used OB Session library, which was not supported for long time, but old code was working just fine.

With move to 3.1.9 we moved the core codebase, however, used old OB Session as a replacement for the moment, and it still works.

But due to wish to increase performance and security, we'd like to move to native Session of CI and this where problems started.

The application we have uses pages loads and makes periodic AJAX calls, which are initiated either on page load finish autoamtically, or by user action, e.g. by click on menu. Within AJAX controllers we need session parameters, e.g. to check access rights for user.

We want to have DB storage, and use MySQL. Initially tried the following settings:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

The problem was that when I load page, and then wait 5 minutes (time for session update) the new session ID was generated and saved in DB table, however, the old one was not removed. So it was left there for garbage collector to remove it later. Due to heavy use on the site, we don't want session table to explode, and would like to have just one latest session ID record in DB for active user.

For this I tried last parameter, which seems to be responsible for this and set:
$config['sess_regenerate_destroy'] = TRUE;

After this the situation worsen, and each page load was generating new session ID record. If there is ajax call on the same page, then e.g. when user loads one page and then ajax call is initiated, there appear two new Session ID records in database. And basically each new page load adds new records to Session table, and old records are not deleted at all.

We load session only in autoload config.

Will appreciate any advice here. What we want is to have one Session ID associated with one user stored in DB. If session ID is regenerated, then previous entry to be removed. Also if the same page loads and same session ID to be used for page load and also for all ajax calls of the same user from the same browser.

Thank you for help in advance!


  Display error log
Posted by: imabot - 10-07-2018, 01:41 AM - Forum: General Help - Replies (2)

In the admin back office of my website, I would like to display logged errors (located in /application/logs). Is there a simple way to do that or should we parse the files with file_get_contents ?



  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.