Please help me with file upload with text fields in codeigniter
Please help me with file upload with text fields details going to database in codeigniter. 开发者_如何学Python( for example i want image name and some another form field going to database and file uploads to server)
Also how do i stop the form submission in database upon page resfresh ?
The best I can do is link you to the relevant pages so that you can learn more. If you provide more information I might be able to help you more:
File upload:
http://codeigniter.com/user_guide/libraries/file_uploading.html
Database:
http://codeigniter.com/user_guide/database/index.html
I recommend using the Active Record part of the database library:
http://codeigniter.com/user_guide/database/active_record.html
As for how to stop form submission on page refresh, simply use redirect('controller/method'); after you have handled the form data. For example:
if(!is_bool($this->input->post('fieldvalue'))
{
$this->model->writeToDB($_POST);
redirect('controller/method');
}
so that every time data is submitted, it is added to the db and then the redirect will revisit the page, thus the browser won't remember what was in the post array and that will solve the problem.
view:
<form method="post" action="#">
<input type="text" name="foo"/>
<input type="submit"/>
</form>
controller:
$this->load->model('yourmodel','model',true);
if(isset($_POST['text']))
$result = $this->model->doQuery($_POST['text']);
model:
function doQuery($text){
$result = $this->db->query("insert into table $text");
return $result;
}
(edit) upload:
use $_FILES and move_uploaded file
精彩评论