Php Codeigniter上载图像并插入到我的文件夹
我正在使用codeigniter,我有一个表单,可以在其中添加一个新项目 在这个表单中,我有一个字段,可以在其中上载图像并插入到数据库中 所有这些都可以插入到我的数据库中 我的问题是,如何将上传到文件夹中的图像添加到文件夹中 路径:Php Codeigniter上载图像并插入到我的文件夹,php,javascript,html,codeigniter,Php,Javascript,Html,Codeigniter,我正在使用codeigniter,我有一个表单,可以在其中添加一个新项目 在这个表单中,我有一个字段,可以在其中上载图像并插入到数据库中 所有这些都可以插入到我的数据库中 我的问题是,如何将上传到文件夹中的图像添加到文件夹中 路径:项目名称/imagens/banner/ 这是我的控制器: function novo(){ $this->load->helper(array('form', 'url')); $this->load->library('f
项目名称/imagens/banner/
这是我的控制器:
function novo(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('banda', 'Banda', 'required');
$this->form_validation->set_rules('data', 'Data', 'required');
$this->form_validation->set_rules('hora_inicio', 'Hora In�cio', 'required|numeric');
$this->form_validation->set_rules('hora_fim', 'Hora Fim', 'required|numeric');
$this->form_validation->set_rules('morada', 'Morada', 'required');
$this->form_validation->set_rules('preco', 'Pre�o', 'required|numeric');
$this->form_validation->set_rules('aquisao_bilhetes', 'Aquisi��o de Bilhetes', 'required');
$this->form_validation->set_rules('descricao', 'Observações', 'required');
$this->form_validation->set_rules('image', 'Imagem', 'required|[image/jpeg|image/png]|file_path[../../imagens/banner/]');
if ( ! $this->input->post())
{
$this->load->view("concertForm");
}
else
{
$dados=$this->input->post();
$this->load->model("Dados_model");
$results = $this->Dados_model->insere($dados);
}
}
也许这对你的问题有帮助 1初始化上载类 与CodeIgniter中的大多数其他类一样,Upload类在控制器中使用$this->load->library函数初始化:
$this->load->library('upload');
2设置首选项
与其他库类似,您将根据自己的首选项控制允许上载的内容。在上面构建的控制器中,可以设置以下首选项:
$config['upload_path'] = './uploads/'; //you can change this set preferences for folder upload
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
您可以选中此项您是否希望在数据库中存储对图像的引用(即:您有一个文件名为filename的列,并在其中存储:myupload.jpg),或者您是否实际希望在数据库中存储图像 如果它是第一个,那么您需要使用
$this->upload->data()
help函数获取有关文件的信息
干杯阅读手册,然后发布上传代码您的问题是否与处理文件上传的CI API有关,或者您不确定如何将上传的文件“存储”到db中?@MarcelloRomani:我的问题是如何将图像添加到文件夹中。。因为对数据库来说,它工作得很好,你已经有了答案,那么(提示:看我的评论上方):-)你能帮我写代码吗?对不起,伙计。我认为在线手册中的复制粘贴是不公平的。为什么只需点击一下就可以复制文本,而不添加任何内容?只要提供指针,OP就可以阅读,如果他对那里的内容有疑问,他会带着更多的问题回来。ya usaha dong。。我们必须在未来几年内实现这一目标。。给出一个模型代码和视图代码biar gw tau dimana letak kesalahan代码loSorry,我不会说马来西亚语。