【问题标题】:Please help me with file upload with text fields in codeigniter请帮助我在 codeigniter 中使用文本字段上传文件
【发布时间】:2010-08-11 00:11:10
【问题描述】:

请帮助我将文本字段详细信息上传到 codeigniter 中的数据库。 (例如,我想要图像名称和另一个表单字段去数据库和文件上传到服务器)

另外我如何在页面刷新时停止在数据库中提交表单?

【问题讨论】:

  • 我们需要查看一些代码,因为我们不知道您的网站或数据库是如何工作的。

标签: php codeigniter file-upload


【解决方案1】:

我能做的最好的就是将您链接到相关页面,以便您了解更多信息。如果您提供更多信息,我可能会为您提供更多帮助:

文件上传:

http://codeigniter.com/user_guide/libraries/file_uploading.html

数据库:

http://codeigniter.com/user_guide/database/index.html

我建议使用数据库库的 Active Record 部分:

http://codeigniter.com/user_guide/database/active_record.html

至于如何在页面刷新时停止表单提交,只需使用redirect('controller/method');处理完表单数据后。例如:

if(!is_bool($this->input->post('fieldvalue'))
{
$this->model->writeToDB($_POST);
redirect('controller/method');
}

这样每次提交数据时,都会将其添加到数据库中,然后重定向将重新访问页面,因此浏览器将不记得 post 数组中的内容,这将解决问题。

【讨论】:

  • 是的,上传然后重定向。这样,您的刷新将不会启动另一次上传。
【解决方案2】:

查看:

<form method="post" action="#">
  <input type="text" name="foo"/>
  <input type="submit"/>
</form>

控制器:

 $this->load->model('yourmodel','model',true);
 if(isset($_POST['text']))
    $result = $this->model->doQuery($_POST['text']);

型号:

  function doQuery($text){
      $result = $this->db->query("insert into table $text");
      return $result;
  }

(编辑)上传:

use $_FILES and move_uploaded file

【讨论】:

    猜你喜欢
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2011-11-14
    • 2016-05-12
    • 2019-07-08
    相关资源
    最近更新 更多