• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload image error when hosting

#1
[eluser]Unknown[/eluser]
Dear All,

I am a new developer who prefer in CodeInitor.

I am using codeIgnitor 2.1.0. I am a problem with upload file when it is hosting online.

//upload image
public function img_upload_file() {
$sizes = array(500);
//upload
$config['upload_path'] = './images/' . $this->session->userdata('use_username') . '/';
$config['max_size'] = 50000000; //kb
$config['allowed_types'] = 'gif|jpg|jpeg|png|bmp|tiff';
$this->load->library('upload', $config);
$this->session->set_userdata('upload', $config['upload_path']);
$i = 0;
//upload image
if ($this->upload->do_upload('userfile')) {
$filename = $this->upload->data();
$this->session->set_userdata("filename", $this->session->userdata('use_username') . $filename['file_name']);
$oldw = $filename['image_width'];
$oldh = $filename['image_height'];
foreach ($sizes as $size) {
//resize
$neww = 0;
$newh = 0;
$i++;
$config['image_library'] = 'gd2';
$config['source_image'] = './images/' . $this->session->userdata('use_username') . '/' . $filename['file_name'];
$config['create_thumb'] = false;
$config['maintain_ratio'] = TRUE;
$config['new_image'] = './images/' . $this->session->userdata('use_username') . '/' . $this->session->userdata('use_username') . $filename['file_name'];
if ($oldw >= $size && $oldw > $oldh) {
$neww = $size;
$newh = ($neww * $oldh) / $oldw;
} else if ($oldh >= $size && $oldh > $oldw) {//if width <= height
$newh = $size;
$neww = ($newh * $oldw) / $oldh;
} else {//if widht or height < $size
$neww = $oldw;
$newh = $oldh;
}
$config['width'] = $neww;
$config['height'] = $newh;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
unlink('images/' . $this->session->userdata('use_username') . '/' . $filename['file_name']);
}
return true;
} else {
return false;
}
}

thanks,

Math Man

#2
[eluser]Sanjay Sarvaiya[/eluser]
unset $config variable after Image upload success.
Code:
...
if ($this->upload->do_upload(‘userfile’)) {
unset($config);
.....


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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