1

I noticed there are similar questions but I have tried the proposed solutions and could not come up with a solution.

Here is my development environment:

  • PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli)
  • Server version: Apache/2.2.22 (Ubuntu)
  • Codeigniter_2.1.2

What I'm trying to do is the basic example of the image upload. Here is the controller:

<?php

class Entry extends CI_Controller {

    function __construct() {
        parent::__construct();
        ini_set('memory_limit', "256M");
    }

    function index() {
        $this->load->view('upload_form');
    }

    function upload() {

        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|png|jpg';
        $config['max_size'] = 2048;
        $config['max_width'] = 1024;
        $config['max_height'] = 768;

        $this->load->library('upload', $config);

        if (! $this->upload()->do_upload('file')) {
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('upload_form', $error);
        }
    }

}

?>

And my view file is simply like this:

<?php
    echo form_open_multipart('entry/upload');
    echo form_upload('file');
    echo form_submit('submit', 'Upload Fille');
?>

In the controller, you can see that I've tried setting memory limit to 256MB, I also tried the -1 option. When I set the memory_limit to -1 the computer ran crazy, it froze ((:

Here is the error that I'm getting when I try to upload sth.

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /var/www/giydir/system/core/Common.php on line 358, referer: http://localhost/giydir/entry

The line that the error shows is interesting to me

$_log =& load_class('Log');
hakre
  • 178,314
  • 47
  • 389
  • 754
small_ticket
  • 1,692
  • 5
  • 20
  • 29
  • Did you change settings in php.ini to allow for your file sizes? – user1026361 Oct 23 '12 at 00:03
  • In my php.ini file: - memory_limit = 128M -post_max_size = 10M -upload_max_filesize = 10M – small_ticket Oct 23 '12 at 00:11
  • possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – SomeKittens Oct 23 '12 at 01:09
  • @SomeKittens as I mentioned, there are also other similar questions other than you have pointed but unfortunately, the proposed solution methods (mostly setting the memory_limit) do not work for me. – small_ticket Oct 23 '12 at 06:20

3 Answers3

0

According to your feedback, you're hitting your memory limit of 128M....your in-script setting of 256M doesnt seem to be sticking. Try editing your ini file directly to increase the memory?

user1026361
  • 3,390
  • 3
  • 19
  • 18
  • Unfortunately, it's not working. I also set it to 512M but I still got the error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 523800 bytes) – small_ticket Oct 23 '12 at 00:57
  • That just reflects that you've hit the limit again. Why not just increase the number to something acceptable to your system and able to handle executing your script? – user1026361 Oct 23 '12 at 14:26
  • I've tried "-1" and in that case my computer became unresponsive – small_ticket Oct 23 '12 at 16:51
0

Sorry, this was my mistake. It is solved now.

The line

if (! $this->upload()->do_upload('file')) {

should be

if (! $this->upload->do_upload('file')) {
small_ticket
  • 1,692
  • 5
  • 20
  • 29
0

Increase your memory size in php.ini file. It will solve your problem.

memory_limit = 12M
jtomaszk
  • 5,583
  • 2
  • 26
  • 39
Hacker
  • 1