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

时间:2017-01-23 10:23:10

标签: php codeigniter file-upload localhost

我无法将图像上传到在线文件夹中,但它在localhost上完美运行。

以下是我的代码

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

请帮助找到解决方案 感谢

伙计感谢您的帮助,问题在于服务器中的php版本 我修好了

4 个答案:

答案 0 :(得分:2)

可能是由于php服务器版本及其选择。

1)。记录到您的cpanel帐户

2)。在软件部分,单击"选择PHP版本"。

3).tap" fileinfo" php选项中的chexbox如下图所示。

![tap the "fileinfo chexbox"][and save]

答案 1 :(得分:1)

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

检查此代码。

答案 2 :(得分:1)

在控制器中试用此代码

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

答案 3 :(得分:0)

这是一个文件限制的简单问题,可以通过在xampp-> php-> php.ini或wamp-> php-> php.ini中获得的php.ini文件中的这些设置来解决(不清楚wamp路径,但您在某个PHP文件夹中)-

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

还有一个简单的选项,无需触摸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');

这是示例最大设置,但您可以根据要求进行更改。