文件上传功能在codeigniter goddady托管中不起作用,但在本地机器工作中

时间:2018-01-03 09:02:41

标签: php codeigniter file-upload image-uploading

我在文件夹和数据库中上传图片和文件时遇到了一些问题。我上传到godaddy托管后上传功能不起作用,但它可以在localhost中运行。当我运行它时,它显示“无法上传”消息,数据不会保存在数据库和文件夹中。我希望有人能帮助我

这是我的控制者:

public function prosesupload()
{
    $config['upload_path']          = './gambar/';
    $config['allowed_types']        = 'gif|jpg|png|pdf|docx';
    $config['max_size']             = 10000;
    $config['max_width']            = 5000;
    $config['max_height']           = 5000;

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

    if ( ! $this->upload->do_upload())
    {
        echo 'fail to upload';
    }
    else
    {
        $img = $this->upload->data();
        $gambar = $img['file_name'];

        $data = array(

                'images' => $gambar, );

        $this->db->insert('arc', $data);
        redirect('arc/index');
    }

}

这是我的观点:

<?php echo form_open_multipart('arc/prosesupload');?>

    <br>

    <tr>
        <td><input type="file" name="userfile" size="20" /> </td>


    <td><button class="w3-button w3-right w3-light-grey" type="submit" 
    align="">Upload</button></a></td>


    </tr>
    <?php echo form_close() ?>

1 个答案:

答案 0 :(得分:0)

文件夹。 您似乎缺少上传文件夹的权限。     尝试给予文件夹完全权限并尝试。还要确保在路径上创建目录。 尝试授予文件夹完全权限并尝试使用它。还要确保在路径上创建目录。

You should give name into do_upload 

您应该将名字命名为do_upload

And few changes in code also :

代码中的变化也很少:

<input type="file" name="test_image" />



public function prosesupload()
{
    $config['upload_path']          = './gambar/';
    $config['allowed_types']        = 'gif|jpg|png|pdf|docx';
    $config['max_size']             = 10000;
    $config['max_width']            = 5000;
    $config['max_height']           = 5000;

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

    if ( ! $this->upload->do_upload('test_image'))
    {
        echo 'fail to upload';
    }
    else
    {
        $img = $this->upload->data();
        $gambar = $img['file_name'];

        $data = array(

                'images' => $gambar, );

        $this->db->insert('arc', $data);
        redirect('arc/index');
    }

}