php - CodeIgniter - resizing images causes "out of memory" -


i wrote utility (w/codeigniter 3.0.5) client allows him upload photos, , they're resized web. script has been working fine several months, of sudden he's getting out-of-memory errors, along lines of this:


file name: img_0047.jpg test
resizing image...
new image: /homepages/20/d153810528/htdocs/toolbox/stuff/images/tool_photos/img_0047_resized.jpg
new filename: img_0047_resized.jpg

fatal error: out of memory (allocated 35389440) (tried allocate 4032 bytes) in /homepages/20/d153810528/htdocs/toolbox/cat/libraries/image_lib.php on line 1455



the "resized" images aren't saved.

i know first choice solution allocate more memory php_ini, appears hosting provider -- 1and1 . com -- doesn't allow that; it's set @ hard 120m; i'm guessing don't want customers screwing shared servers.

any thoughts?

here's code handles resizing:

   public function uploadapicture() {  $status = ''; $msg = ''; $file_element_name = 'picture';  if ($status !== 'error') {     $config['upload_path'] = 'stuff/images/tool_photos/';     $config['allowed_types'] = 'gif|jpeg|png|jpg';     $config['max_size'] = 1024 * 50;     $config['encrypt_name'] = false;      $this->load->library('upload',$config);     if (!$this->upload->do_upload($file_element_name)) {         $status = 'error';         $msg = $this->upload->display_errors('','');     } else {         $data = $this->upload->data();         $image_path = $data['full_path'];         if (file_exists($image_path)) {             $status = 'success';             $msg = 'main picture "' . $_files[$file_element_name]['name'] . '" uploaded';         } else {             $status = 'error';             $msg = 'there problem saving main picture.';         }     }     @unlink($_files[$file_element_name]);      $file_element_name = 'thumbnail';     if ((strlen($_files[$file_element_name]['name']) > 0) && !$this->upload->do_upload($file_element_name)) {         $status = 'error';         $msg .= $this->upload->display_errors('','');     } else if (strlen($_files[$file_element_name]['name']) > 0) {         $data = $this->upload->data();         $image_path = $data['full_path'];         if (file_exists($image_path)) {             $status = 'success';             $msg .= 'thumbnail uploaded';         } else {             $status = 'error';             $msg .= 'there problem saving thumbnail.';         }     }     if ($status === 'success') {         echo "<br><pre>post stuff:" . print_r($_post,1);         $tooltoinsert = array(             'picture_filename' => $_files['picture']['name'],             'name' => $this->input->post('name'),             'purchase_price' => $this->input->post('purchase_price'),             'public_notes' => $this->input->post('public_notes'),             'public_misc' => $this->input->post('public_misc'),             'purchased_from' => $this->input->post('purchased_from'),             'private_purchase_date' => $this->input->post('private_purchase_date'),             'private_purchase_price' => $this->input->post('private_purchase_price'),             'purchase_location' => $this->input->post('purchase_location'),             'sold_by' => $this->input->post('sold_by'),             'date_sold' => $this->input->post('date_sold'),             'sale_price' => $this->input->post('sale_price'),             'sold_to_name' => $this->input->post('sold_to_name'),             'sold_to_phone' => $this->input->post('sold_to_phone'),             'sold_to_email' => $this->input->post('sold_to_email'),             'private_notes' => $this->input->post('private_notes'),             'private_misc' => $this->input->post('private_notes'),             'entered_this_year' => $this->input->post('entered_this_year'),             'year_entered' => date('y')          );          if (isset($_files['thumbnail']['name'])) {             $tooltoinsert['thumbnail_filename'] = $_files['thumbnail']['name'];         }         foreach($_post $pkey => $pval) {             if (substr($pkey,0,9) === 'category_') {                 error_log("found category: ".print_r($pval,1)." key of ".print_r($pkey,1));                 $post_category[] = substr($pkey,9);             }         }         if (isset($post_category)) {             $tooltoinsert['category'] = implode(',',$post_category);         }          if (isset($_post['active'])) {             $tooltoinsert['active'] = 1;         }         $this->load->model('letme_model');         $result = $this->letme_model->inserttool('tool_db',$tooltoinsert);         echo "result: \n";         echo print_r($result,1);     }  } echo json_encode(array('status' => $status, 'msg' => $msg)); } 

one way increase memory in php 5.x uploading images in .htaccess

just add lines:

## need more memory upload large image <ifmodule mod_php5.c>     php_value memory_limit 256m  ## or whatever need </ifmodule> 

Comments