I am new to image uploading and would like to request for help about uploading file image into server folder . I am using ajax to send the image to my controller . This is what i received when i var_dump it in the controller. After calling $_FILES['croppedImage'] The result i get is
array(5) { ["name"]=> string(4) "blob" ["type"]=> string(10) "image/jpeg"
["tmp_name"]=> string(14) "/tmp/phpqtmMQu" ["error"]=> int(0) ["size"]=>
int(10686) }
This is my controller function that i use to upload my image into the server folder.
public function upload_base_64(){
$MY_UPLOAD_DIR = "alert_images/";
$imagefilename = basename( $_FILES['croppedImage']['name']);
$fulluploadpath =base_url().'/uploads/'.$MY_UPLOAD_DIR. $imagefilename;
$image_name = strip_tags($_FILES['croppedImage']['name']);
$image_size = getimagesize($_FILES['croppedImage']['tmp_name']);
if($image_size == FALSE) {
echo 'The image was not uploaded';
}
else if(move_uploaded_file($_FILES['croppedImage']['tmp_name'], $fulluploadpath )) {
var_dump('it works');exit;
} else {
echo "Sorry, there was a problem uploading your file.";
}
}
It went to the else condition . I saw a few tutorial having this code but i do not know how to use it and why does it only require name?Doesn't it need the file?
public function uploadfeaturedfile()
{
$dir_name = 'alert_images/';
$config['upload_path'] = './uploads/'.$dir_name;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '5120';
$config['min_width'] = '640';
$config['min_height'] = '640';
$this->load->library('dbcupload', $config);
$this->dbcupload->display_errors('', '');
if($this->dbcupload->do_upload('photoimg'))
{
$data = $this->dbcupload->data();
$this->load->helper('date');
$format = 'DATE_RFC822';
$time = time();
create_rectangle_thumb('./uploads/'.$dir_name.$data['file_name'],'./uploads/thumbs/');
$media['media_name'] = $data['file_name'];
$media['media_url'] = base_url().'uploads/'.$dir_name.$data['file_name'];
$media['create_time'] = standard_date($format, $time);
$media['status'] = 1;
$status['error'] = 0;
$status['name'] = $data['file_name'];
}else{
$errors = $this->dbcupload->display_errors();
$errors = str_replace('<p>','',$errors);
$errors = str_replace('</p>','',$errors);
$status = array('error'=>$errors,'name'=>'');
}
echo json_encode($status);
die;
}
All help are really appreciated!!! Please and thanks in advance.