画像アップローダーがあり、スタックしているように見える CodeIgniter でフォームを構築しようとしています。ファイルのアップロードをコメントアウトするとデータベースの送信は機能しますが、ファイルアップローダーを元に戻しても何も起こりません。これを実行してもエラーは発生しません。
明らかな何かが欠けていると確信していますが、それが何であるかを一生理解することはできません。どんな助けでも大歓迎です!
コントローラ
public function Upload()
{
$data['segment'] = 'Contact us';
// Checks if user is logged in
if ( $this->session->userdata('logged_in') === TRUE) {
$data['user'] = $this->session->userdata('username');
}
else {
$data['user'] = null;
}
$url = base_url();
$config['upload_path'] = './uploads/';
// Load an initialize
$this->load->helper('form');
$this->load->library('form_validation');
$this->upload->initialize($config);
$this->form_validation->set_rules("name", '"name"', 'required|trim|max_length[30]|xss_clean');
// Uploads file
if (! $this->upload->do_upload('userfile')) {
$data['error'] = array('error' => $this->upload->display_errors());
}
else {
$data = array('upload_data' => $this->upload->data());
$img_data = $this->upload->data();
if (FALSE !== $this->form_validation->run()) {
// Database submission
$submission = new ReptileModel();
$submission->name = $this->input->post("name");
$submission->sex = $this->input->post("sex");
$submission->hatch_date = $this->input->post("date");
$submission->morph = $this->input->post("morph");
$submission->weight = $this->input->post("weight");
$submission->price = $this->input->post("price");
$submission->reptile_id = $this->input->post("rid");
$submission->description = $this->input->post("description");
$submission->image = $img_data['file_name'];
if ($submission->save()) {
redirect('main/index');
}
else {
$this->session->set_flashdata('message','Not uploaded');
}
}
}
$this->upload->display_errors();
$this->load->view('header', $data);
if ( $this->session->userdata('logged_in') === TRUE) {
$this->load->view('admin/reptileUpload', $data);
}
else {
redirect('main/index');
}
$this->load->view('footer');
ページを見る
<?php
$rname_field = array(
'name' => 'name',
'id' => 'name',
'value' => set_value('name')
);
$rsex_field = array(
'name' => 'sex',
'id' => 'sex',
'value' => set_value('sex'),
'placeholder' => 'Male or female'
);
$rdate_field = array(
'name' => 'date',
'id' => 'date',
'value' => set_value('date'),
'placeholder' => 'January 1, 2100'
);
$rmorph_field = array(
'name' => 'morph',
'id' => 'morph',
'value' => set_value('morph')
);
$rweight_field = array(
'name' => 'weight',
'id' => 'weight',
'value' => set_value('weight'),
'placeholder' => 'Please only put a number, no letters.'
);
$rprice_field = array(
'name' => 'price',
'id' => 'price',
'value' => set_value('price'),
'placeholder' => 'The price with a decimal, but no dollar sign.'
);
$rid_field = array(
'name' => 'rid',
'id' => 'rid',
'value' => set_value('rid')
);
$rdescriptione_field = array(
'name' => 'description',
'id' => 'description',
'value' => set_value('description'),
'rows' => '5',
'placeholder' => 'A short descrition.'
);
?>
<?php echo $error;?>
<div class="row">
<?php print form_open_multipart('admin/upload'); ?>
<fieldset class="form-wrapper">
<div class="large-8 columns">
<div class="row">
<div class="large-6 columns">
<div class="form-field">
<label for="name">Name:<br /></label>
<?php echo form_input($rname_field); ?>
</div>
</div>
<div class="large-6 columns">
<div class="form-field">
<label for="sex">Sex:<br /></label>
<?php echo form_input($rsex_field); ?>
</div>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<div class="form-field">
<label for="date">Hatch Date:<br /></label>
<?php echo form_input($rdate_field); ?>
</div>
</div>
<div class="large-6 columns">
<div class="form-field">
<label for="morph">Morph:<br /></label>
<?php echo form_input($rmorph_field); ?>
</div>
</div>
</div>
<div class="row">
<div class="large-4 columns">
<div class="form-field">
<label for="weight">Weight:<br /></label>
<?php echo form_input($rweight_field); ?>
</div>
</div>
<div class="large-4 columns">
<div class="form-field">
<label for="price">Price:<br /></label>
<?php echo form_input($rprice_field); ?>
</div>
</div>
<div class="large-4 columns">
<div class="form-field">
<label for="rid">ID:<br /></label>
<?php echo form_input($rid_field); ?>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="form-field">
<label for="description">Description:<br /></label>
<?php echo form_textarea($rdescriptione_field); ?>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="form-field">
<input type="file" name="userfile" id="image" />
</div>
</div>
</div>
</div>
<div class="large-4 columns">
<div class="row">
<div class="large-12 columns">
<div class="form-actions">
<input class="button success" type="submit" name="submit" value="Send »" />
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<input class="button alert" type="reset" name="reset" value="Clear" />
</div>
</div>
<div class="row">
<div class="large-12 columns">
<?php print validation_errors('<div data-alert class="alert-box alert">', '<a href="#" class="close">×</a></div>'); ?>
</div>
</div>
</div>
</fieldset>
</div>
<?php print form_close();?>
</div>