Skip to content

Instantly share code, notes, and snippets.

@seanmcn
Created December 3, 2014 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanmcn/9f0088a913ff6434f525 to your computer and use it in GitHub Desktop.
Save seanmcn/9f0088a913ff6434f525 to your computer and use it in GitHub Desktop.
<?php
public function uploadImage() {
$this->load->library('upload');
$imageFolder = 'assets/images/features';
if (!file_exists($imageFolder)) {
mkdir($imageFolder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $imageFolder,
'allowed_types' => '*',
'max_size' => 2048,
'remove_space' => TRUE,
'encrypt_name' => TRUE
);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$fileNames= array();
$fileNames= $this->session->userdata('featureImages');
$fileInfo = $this->upload->data();
$fileNames[] = $fileInfo['file_name'];
$this->session->set_userdata('featureImages', $fileNames);
echo json_encode($fileInfo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment