【问题标题】:file upload function does not working in codeigniter goddady hosting but in local machine work文件上传功能在 codeigniter godaddy 托管但在本地机器工作中不起作用
【发布时间】:2018-01-03 09:02:41
【问题描述】:

我在上传文件夹和数据库中的图像和文件时遇到了一些问题。上传到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() ?>

【问题讨论】:

  • 尝试输出上传错误。所以你可能会发现哪里出了问题。 $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
  • 你的助手可能有问题看看 $this->load->helper(array('form', 'url'));
  • @Badiparmagi,我已经做了你的代码,但它显示空白页
  • @omkara,我需要做 upload_helper.php 吗?因为我做了你的代码,它显示消息“文件不存在-helpers/upload_helper.php”
  • 如果有linux主机比检查文件夹的权限

标签: php codeigniter file-upload image-uploading


【解决方案1】:

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

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

}

【讨论】:

  • 我已经按照你的代码,但它仍然错误..我的文件夹在根目录“项目”中
  • 我使用了 print_r($_FILES) 并显示错误失败 uploadArray ( [userfile] => Array ( [name] => images (3).jpg [type] => image/ jpeg [tmp_name] => C:\Windows\Temp\phpF62A.tmp [error] => 0 [size] => 16046 ))..我该怎么办?我是codeigniter的新手..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-23
  • 2014-11-12
  • 1970-01-01
  • 2015-08-11
  • 2021-06-03
相关资源
最近更新 更多