简体   繁体   English

Codeigniter文件上传在Live Server上不起作用

[英]Codeigniter File Upload Not Working On Live Server

I cant upload the image into the folder online, but it works perfectly on localhost. 我无法将图像在线上传到文件夹中,但是在localhost上可以完美运行。

Below Is My Code 以下是我的代码

$this->load->helper(array('form', 'url'));
if (empty($_FILES['photo']['name'])) {
    $image=$this->input->post('image');
} else {
    $config = array(
        'upload_path' => "uploads/",
        'allowed_types' => "gif|jpg|png|jpeg",
    );
    $this->load->library('upload',$config); 

    if($this->upload->do_upload('photo')) {
        $upload_data = $this->upload->data();
        $image = $upload_data['file_name'];
    } else {
        $error = array('error' => $this->upload->display_errors());
        redirect(base_url().'uploaderror');
    }
}

Please help finding the solution Thanks 请帮助找到解决方案,谢谢

Guys Thanks for your help the problem was with the php version in the server i fixed it 伙计们感谢您的帮助,问题出在服务器中的php版本中,我已将其修复

it may be due to php server version and it's option. 这可能是由于php服务器版本及其选择。

1).logging to your cpanel account 1)。登录到您的cpanel帐户

2).in the software section,click "Select PHP Version". 2)。在“软件”部分中,单击“选择PHP版本”。

3).tap the "fileinfo" chexbox in the php option like following photo. 3)。点击php选项中的“ fileinfo” chexbox,如下图所示。

![tap the "fileinfo chexbox"][and save] ![点击“ fileinfo chexbox”] [并保存]

$base_path = $this->config->item('upload_path');

        $config['upload_path'] = $base_path.'/folder_name/';
        $config['allowed_types'] = config('allowed_extensions');
        $config['max_size'] = config('max_upload_file_size');
        $config['encrypt_name'] = true;
        $file_name = '';

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

check this code. 检查此代码。

Try this code in your controller 在您的控制器中尝试此代码

<?php
        public function _upload_files()
        {
                $this->session->unset_userdata('upload_data');
                $config['upload_path']          = FCPATH.'uploads'.DIRECTORY_SEPARATOR;
                $this->_check_file_upload_path($config['upload_path']);// check if upload path exists, if not creates one
                $config['allowed_types']        = "gif|jpg|png|jpeg";
                $config['encrypt_name']         = TRUE;// file name will be encrypted
                $this->load->library('upload', $config);
                if ( !$this->upload->do_upload('photo'))
                {
                        echo $this->upload->display_errors('','');
                        return FALSE;
                }       
                var_dump($this->upload->data());

        }

        private function _check_file_upload_path($upload_path)
        {
                if(! is_dir($upload_path))
                        mkdir($upload_path,0777,TRUE);
                return $upload_path;
        }

It's a simple problem of file limit and it may be solved by these setups in your php.ini file which you get in xampp->php->php.ini or in your wamp->php->php.ini (not clear about wamp path but you somewhere PHP folder) - 这是一个简单的文件限制问题,可以通过在xampp-> php-> php.ini或wamp-> php-> php.ini中获得的php.ini文件中的这些设置来解决(不清楚沼泽路径,但你在某个地方的PHP文件夹)-

post_max_size=1024M
upload_max_size=1500M
memory_limit=128M //For unlimited set -1
max_execution_time=3600

There is another easy option without touching the php.ini file is just you define them in your controller or where ever 还有一个简单的选项,无需触摸php.ini文件,只需在控制器中或任何位置定义它们

ini_set('post_max_size','99500M');
ini_set('upload_max_size','100000M');
ini_set('memory_limit','128M');
ini_set('max_execution_time','5000');

It's sample max setup but you change as per your requirment. 这是最大设置示例,但您可以根据需要进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM