无法在codeigniter中上传大文件

时间:2014-05-05 08:38:05

标签: php codeigniter file-upload

我在上传较大的文件时遇到问题,然后在CI中上传2MB。我的网站在one.com的服务器上运行。 PHP.ini中的最大上传大小为96MB。所以我想这没关系。我的.htaccess中有一些行,但上传后仍然是白屏,没有错误。有什么建议我如何上传更大的图像然后2MB? 2MB以下的上传效果非常好。

.htaccess

php_value upload_max_filesize 96M
php_value post_max_size 96M
php_value max_execution_time 200
php_value max_input_time 200

控制器

function voegfotostoe()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '0';
    $config['max_width']  = '0';
    $config['max_height']  = '0';
    $this->load->library('upload', $config);    
    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
    }   
    $datap = array('upload_data' => $this->upload->data());

    $id = $this->input->post('id');

    $gallery_path = realpath(APPPATH . '/../uploads');

    $upload_data = $this->upload->data();

    $this->load->library('image_lib');

    /* Size 200px x 200px */
    $config['image_library'] = 'gd2';
    $config['source_image'] = $upload_data['full_path'];
    $config['new_image'] = $gallery_path . '/thumbs';
    $config['create_thumb'] = FALSE;
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 350;
    $config['height'] = 300;

    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();


    $config['image_library'] = 'gd2';
    $config['source_image'] = $upload_data['file_path'] . 'thumbs/' . $upload_data['orig_name'];
    $config['new_image'] = $gallery_path . '/vierkant';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = FALSE;
    $config['width'] = 200;
    $config['height'] = 200;

    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->crop();


    $thumb = $this->upload->data();
    $thumbname = $thumb['raw_name'] . $thumb['file_ext'];

    /* Size 600px X 600px */

    $config['image_library'] = 'gd2';
    $config['source_image'] = $upload_data['full_path'];
    $config['new_image'] = $gallery_path . '/medium';
    $config['thumb_marker'] = '_medium';
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 500;
    $config['height'] = 500;

    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    $medium = $this->upload->data();
    $mediumname = $medium['raw_name'] . '_medium'. $medium['file_ext'];

$data = array(
    'fk_land' => $this->input->post('landid'),
    'titel' => $this->input->post('titel'),
    'period' => $this->input->post('period'),
    'size' => $this->input->post('size'),
    'info' => $this->input->post('info'),
    'region' => $this->input->post('region'),
    'cat_id' => $this->input->post('catsculp'),
    'color' => $this->input->post('color'),
    'order' => $this->input->post('landtoevoegen'),
    'gallery_name' => $this->input->post('painter'),
    'thumb_img' => $thumbname,
    'medium_img' => $mediumname

);

    if( $datap['upload_data']['orig_name'] != "" ) $data['gallery_img'] = $datap['upload_data']['orig_name'];
    $this->Cms_model->voegfototoe($data);
    redirect('home#toevoegen','refresh');   
}

2 个答案:

答案 0 :(得分:2)

使用帖子表单时遇到同样的问题,请在php.ini中查看您拥有的行:" post_max_size"并将其更改为您想要的示例8M或0为无限。

答案 1 :(得分:0)

即使您将自己的php.ini文件和.htaccess放在服务器的根目录中,服务器也无法更改其默认设置。如果您尝试phpinfo(),将显示本地和服务器值。如果您的本地值不同,则您无权更改。您应该与服务器提供商联系。