【发布时间】: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' => $this->upload->display_errors()); -
你的助手可能有问题看看 $this->load->helper(array('form', 'url'));
-
@Badiparmagi,我已经做了你的代码,但它显示空白页
-
@omkara,我需要做 upload_helper.php 吗?因为我做了你的代码,它显示消息“文件不存在-helpers/upload_helper.php”
-
如果有linux主机比检查文件夹的权限
标签: php codeigniter file-upload image-uploading