Skip to content

Instantly share code, notes, and snippets.

@anabelle
Created January 21, 2012 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anabelle/1654509 to your computer and use it in GitHub Desktop.
Save anabelle/1654509 to your computer and use it in GitHub Desktop.
Function to get an email using Sendgrid Parse API and save attachments using CodeIgniter
<?php
# CI Reference: http://codeigniter.com/user_guide/libraries/file_uploading.html
# SendGrid Reference: http://docs.sendgrid.com/documentation/api/parse-api-2/
public function input(){
//file upload configuration
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '8192';
$config['max_width'] = '0';
$config['max_height'] = '0';
//load the upload library
$this->load->library('upload', $config);
if(intval($_POST['attachments']) > 0){
if(intval($_POST['attachments']) == 1){
if ($this->upload->do_upload('attachment1')){
echo 'subio';
}else{
echo $this->upload->display_errors();
}
}else{
$cont = 1;
while($cont <= intval($_POST['attachments'])){
//repeat the action for each file
if ($this->upload->do_upload('attachment'.$cont)){
echo 'subio';
}else{
echo $this->upload->display_errors();
}
//go to the next file
$cont++;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment