Codeigniter图片上传不工作 [英] Codeigniter image upload not working

查看:112
本文介绍了Codeigniter图片上传不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我做什么,我都无法上传我的图片。下面是我的模型中的代码:

I can't get my images to upload no matter what i do. Below is the code that is in my model:

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

这是我的控制器中的代码:

Here is the code that is in my controller:

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,它真的让我在一个死胡同。除此之外,我想能够将文件的路径写入我的数据库,但我不能想出来,所以如果有人有一个答案,甚至指出我的正确方向,我会非常感谢。
感谢

Can someone tell me what it is that i'm doing wrong? I'm a complete newbie to codeigniter and it is really leaving me at a dead end. As well as this I want to be able to write the path of the file to my database but i can't figure that out either so if someone has an answer or even point me in the right direction I would be extremely grateful. Thanks

编辑-----------

EDIT -----------

上传太高/宽。但是如果有人能指出我如何写数据库的文件路径,这将是巨大的!

The image i was uploading was too tall/wide. But if someone could point me in the direction of how to write the filepath to the database, that would be great!

推荐答案

类似于一个项目 - 基本上你只需要把路径变成一个字符串并写入你的数据库...

Did something similar with a project - basically you just need to turn the path into a string and write it to your db...

$fileup = $this->upload->data();
    $myfilepath = $fileup['file_name'];
    $databack = array(
        'your_field'=> 'http://www.yourserver.com/location/'.$myfilepath.'',
    ); 
    $DB->where('your_id_field', $id_value);
    $DB->update('your_table', $databack);  

最棘手的就是将它绑到数据库!

The trickiest bit is just tying it to your database!

这篇关于Codeigniter图片上传不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆