【发布时间】:2010-05-07 13:04:11
【问题描述】:
无论我做什么,我都无法上传我的图片。以下是我的模型中的代码:
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
return $error;
}
else
{
$data = array('upload_data' => $this->upload->data());
return $data;
}
这是我的控制器中的代码:
function do_upload()
{
$this->Upload_model->do_upload();
}
这是我的表格:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo form_open_multipart('upload/do_upload');?>
<?php if(isset($buttons)) : foreach($buttons as $row) : ?>
<h2><?php echo $row->name; ?></h2>
<input type="file" name="userfile" size="20" />
<input type="hidden" name="oldfile" value="<?php echo $row->image_url; ?>" />
<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<br /><br />
<label>Url: </label><input type="text" name="url" value="<?php echo $row->url; ?>" /><br /><br />
<input type="submit" value="submit" />
</form>
<?php endforeach; ?>
<?php endif; ?>
</body>
</html>
谁能告诉我我做错了什么?我是codeigniter的新手,它真的让我陷入了死胡同。除此之外,我希望能够将文件的路径写入我的数据库,但我也无法弄清楚,所以如果有人有答案,甚至指出我正确的方向,我将非常感激。 谢谢
编辑-----------
我上传的图片太高/太宽。但是,如果有人能指出如何将文件路径写入数据库的方向,那就太好了!
【问题讨论】:
-
$config['max_size'] = '100';表示最大文件大小为 100 字节,这是您想要的吗?还有什么错误? -
唉,我没有收到任何错误,而且不是文件大小。
-
我是个白痴。高度和宽度太大了!
标签: php codeigniter