我们正在开发基于CI框架的社交网络项目。我在网上搜索,但感到困惑。如何上传照片,允许用户裁剪照片并使用数据库保存,以便在通话时检索照片?我正在使用这个资料图片。使用Codeigniter进行照片上传,裁剪和保存
在视图:
<?php echo form_open_multipart ('index.php/Main/do_upload'); ?>
<table class="table">
<tr>
<td>Title</td>
<td><?php echo form_input('title'); ?></td>
</tr>
<tr>
<td>Image</td>
<td><?php echo form_upload('userfile'); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"'); ?></td>
<?php echo form_close(); ?>
</tr>
</table>
在控制器:
public 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('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('Material_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
你到目前为止尝试过什么。用那个更新你的问题。所以我们将为您提供改进代码的步骤。 –
首先在视图上我使用php表单创建了表单,然后在控制器上创建函数do_upload()。我参考了它,但它没有奏效。 – Aryan
为什么不能提供代码。如果你提供的话,这对于纠正错误权利将是有用的。 –