Ich schrieb ein Dienstprogramm (w/CodeIgniter 3.0.5) für einen Client, mit dem er Fotos hochladen kann, und sie sind für das Internet Größe geändert. Das Skript arbeitet seit mehreren Monaten in Ordnung, aber ganz plötzlich er Fehler out-of-Speicher bekommen, entlang der Linien von dieser:CodeIgniter - Größe ändern Bilder verursacht "nicht genügend Arbeitsspeicher"
Dateiname: IMG_0047.JPG Test
Bild Ändern der Größe. ..
New Bild: /homepages/20/d153810528/htdocs/toolbox/stuff/images/tool_photos/IMG_0047_resized.JPG
Neuer Dateiname: IMG_0047_resized.JPG
Fatal error: Out of memory (allocated 35389440) (tried to allocate 4032 bytes) in /homepages/20/d153810528/htdocs/toolbox/cat/libraries/Image_lib.php on line 1455
Die "skalierten" Bilder werden nicht gespeichert.
Ich weiß, die erste Wahl Lösung ist mehr Speicher mit php_ini zuweisen, aber es scheint, dass der Hosting-Provider - 1and1. com - erlaubt das nicht; es ist auf eine harte 120M eingestellt; Ich nehme an, sie wollen nicht, dass Kunden mit ihren gemeinsam genutzten Servern herumhauen.
Irgendwelche Gedanken?
Hier ist der Code, der die Redimensionierung Griffe:
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'] . '" successfully uploaded';
} else {
$status = 'error';
$msg = 'There was a problem saving the 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 successfully uploaded';
} else {
$status = 'error';
$msg .= 'There was a problem saving the 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 as $pKey => $pVal) {
if (substr($pKey,0,9) === 'category_') {
error_log("Found a category: ".print_r($pVal,1)." for 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));
}
Es gibt viel zu viel für uns, um hier durchzukommen. Sie müssen Ihren Code mit 'echo memory_get_usage (true); exit(); "genau herausfinden, woher die Überlastung des Gedächtnisses kommt und dann können wir einen Rat geben. – Ohgodwhy