Codeigniter - 上传时允许内存大小耗尽 [英] Codeigniter - Allowed memory size exhausted while uploading

查看:292
本文介绍了Codeigniter - 上传时允许内存大小耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到有类似的问题,但我已经尝试了提出的解决方案,并且不能提出解决方案。



这是我的开发环境:




  • PHP 5.3.10-1ubuntu3.4与Suhosin-Patch(cli)

  • 服务器版本:Apache / 2.2 .22(Ubuntu)

  • Codeigniter_2.1.2



我想做的是图像上传的基本示例。这是控制器:

 <?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);
}
}

}

?>

我的视图文件就像这样:

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

在控制器中,您可以看到我已经尝试将内存限制设置为256MB, -1选项。当我将memory_limit设置为-1的计算机运行疯了,它冻结((



这是我得到的错误,当我尝试上传sth。 / p>

  PHP致命错误:在/ var / www / giydir / system中允许内存大小为134217728字节用尽(试图分配523800字节) /core/Common.php on line 358,referer:http:// localhost / giydir / entry 

错误显示的行对我很有趣

  $ _ log =& load_class('Log'); 
对我有用[0]丢个板砖[0]引用举报顶(0)踩(0)@

>

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

应为

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


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');

解决方案

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')) {

这篇关于Codeigniter - 上传时允许内存大小耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆