Php 设置_值对HMVC Codeigniter上的输入类型文件无效

Php 设置_值对HMVC Codeigniter上的输入类型文件无效,php,html,codeigniter,Php,Html,Codeigniter,我正在为我的项目使用HMVC Codeigniter模式。在我的项目中,我需要在表单上设置值,其中字段的输入类型是file。所以,我为帮助我解决这个问题的人感到非常感谢 我的助理控制器是apply.php <?php class Career extends Controller{ function __construct(){ parent::__construct(); $this->load->Model('career_model','

我正在为我的项目使用HMVC Codeigniter模式。在我的项目中,我需要在表单上设置值,其中字段的输入类型是file。所以,我为帮助我解决这个问题的人感到非常感谢

我的助理控制器是apply.php

<?php
class Career extends Controller{
function __construct(){
        parent::__construct();

        $this->load->Model('career_model','',TRUE);
        $this->load->model('welcome/Mwelcome','',TRUE);     
        //session_start();
    }
finction index(){
redirect('career/apply');
}
  function apply(){
        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->form_validation->set_rules('fname','First Name','required|trim');
        $this->form_validation->set_rules('mname','Middle Name','required|trim');
        $this->form_validation->set_rules('lname','Last Name','required|trim');
        $this->form_validation->set_rules('date','Date','required|trim');
        $this->form_validation->set_rules('pAddress','Permanent Address','required|trim');
        $this->form_validation->set_rules('cAddress','Contact Address','required|trim');
    $this->form_validation->set_rules('gender','Gender','required|trim');

        if (empty($_FILES['cv']['name']))
        {
            $this->form_validation->set_rules('cv', 'Attach Your CV', 'required');
        }
        if($this->form_validation->run($this)){

                    $_SESSION['msg']="Your form has been submitted succesfully!!";
                    redirect('career/apply');
                }
                else
                {

                    $_SESSION['err']="Opp! There was some wrong to fill up a form so try again!!!";
                    redirect('career/apply');


                }

            }
        $data=array('body'=>'apply');
        $data['pgtitle']='Apply';       
        $this->load->view('temp',$data);
        } 
}
<form action="<?php echo site_url()?>career/apply" method="post" enctype="multipart/form-data" onsubmit="return confirm('Do you really want to submit the form?');">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">


    <tr>
      <td width="">Name</td>
      <td width="158"><label for="fname"></label>
      <input type="text" name="fname" id="fname" placeholder="First Name" class='input-row' value="<?php echo set_value('fname')?>"/><span class="required"><?php echo form_error('fname');?></span></td>
      <td width="158"><label for="mname"></label>
      <input type="text" name="mname" id="mname" placeholder="Middle Name" class='input-row' value="<?php echo set_value('mname')?>"/></td>
      <td width="158"><label for="lname"></label>
      <input type="text" name="lname" id="lname" placeholder="Last Name" class='input-row' value="<?php echo set_value('lname')?>"/><span class="required"><?php echo form_error('lname');?></span></td>
    </tr>

    <tr>
      <td>Date of Birth</td>
      <td width="158"><label for="date"></label>
      <input type="text" name="date" id="date" class='input-row' value="<?php echo set_value('date')?>" placeholder="yyyy-mm-dd"/><span class="required"><?php echo form_error('date');?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
   <tr>
      <td>Gender</td>
      <td><div class="customSel">
        <label>
        <select name="gender" id="select" class='input-row' value="">

         <option value="Female"<?php echo  set_select('gender', 'Female', TRUE); ?>>Female</option>
         <option value="Male"<?php echo  set_select('gender', 'Male', TRUE); ?>>Male</option>
         <option value="Please Selection"<?php echo  set_select('gender', 'Please Selection', TRUE); ?>>Please Selection</option>
         <?php /*?><option value="Other"<?php echo  set_select('gender', 'Other', TRUE); ?>>Other</option><?php */?>
      </select></label></div><span class="error"><?php echo form_error('gender')?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label for="pAddress"></label>
      <input type="text" name="pAddress" id="pAddress" placeholder="Permanent Address" class='input-row' value="<?php echo set_value('pAddress')?>"/><span class="required"><?php echo form_error('pAddress');?></span></td>
      <td><label for="cAddress"></label>
      <input type="text" name="cAddress" id="cAddress" placeholder="Contact Address" value="<?php echo set_value('cAddress')?>"/><span class="required"><?php echo form_error('cAddress');?></span></td>
      <td>&nbsp;</td>
    </tr> 
    <tr>
      <td>Attach Your CV</td>
      <td colspan="2"><label for="cv"></label>
      <input type="file" name="cv" id="cv" value="<?php echo set_value('cv')?>"/><span class="error"><?php echo form_error('cv')?></span></td>
    </tr>
    <tr>

      <td><input type="submit" name="submit" id="submit" value="Submit" class="Button" />

        <input type="reset" name="reset" id="reset" value="Reset" class="Button" /></td>

      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form >
我的关联视图文件是apply.php

<?php
class Career extends Controller{
function __construct(){
        parent::__construct();

        $this->load->Model('career_model','',TRUE);
        $this->load->model('welcome/Mwelcome','',TRUE);     
        //session_start();
    }
finction index(){
redirect('career/apply');
}
  function apply(){
        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->form_validation->set_rules('fname','First Name','required|trim');
        $this->form_validation->set_rules('mname','Middle Name','required|trim');
        $this->form_validation->set_rules('lname','Last Name','required|trim');
        $this->form_validation->set_rules('date','Date','required|trim');
        $this->form_validation->set_rules('pAddress','Permanent Address','required|trim');
        $this->form_validation->set_rules('cAddress','Contact Address','required|trim');
    $this->form_validation->set_rules('gender','Gender','required|trim');

        if (empty($_FILES['cv']['name']))
        {
            $this->form_validation->set_rules('cv', 'Attach Your CV', 'required');
        }
        if($this->form_validation->run($this)){

                    $_SESSION['msg']="Your form has been submitted succesfully!!";
                    redirect('career/apply');
                }
                else
                {

                    $_SESSION['err']="Opp! There was some wrong to fill up a form so try again!!!";
                    redirect('career/apply');


                }

            }
        $data=array('body'=>'apply');
        $data['pgtitle']='Apply';       
        $this->load->view('temp',$data);
        } 
}
<form action="<?php echo site_url()?>career/apply" method="post" enctype="multipart/form-data" onsubmit="return confirm('Do you really want to submit the form?');">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">


    <tr>
      <td width="">Name</td>
      <td width="158"><label for="fname"></label>
      <input type="text" name="fname" id="fname" placeholder="First Name" class='input-row' value="<?php echo set_value('fname')?>"/><span class="required"><?php echo form_error('fname');?></span></td>
      <td width="158"><label for="mname"></label>
      <input type="text" name="mname" id="mname" placeholder="Middle Name" class='input-row' value="<?php echo set_value('mname')?>"/></td>
      <td width="158"><label for="lname"></label>
      <input type="text" name="lname" id="lname" placeholder="Last Name" class='input-row' value="<?php echo set_value('lname')?>"/><span class="required"><?php echo form_error('lname');?></span></td>
    </tr>

    <tr>
      <td>Date of Birth</td>
      <td width="158"><label for="date"></label>
      <input type="text" name="date" id="date" class='input-row' value="<?php echo set_value('date')?>" placeholder="yyyy-mm-dd"/><span class="required"><?php echo form_error('date');?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
   <tr>
      <td>Gender</td>
      <td><div class="customSel">
        <label>
        <select name="gender" id="select" class='input-row' value="">

         <option value="Female"<?php echo  set_select('gender', 'Female', TRUE); ?>>Female</option>
         <option value="Male"<?php echo  set_select('gender', 'Male', TRUE); ?>>Male</option>
         <option value="Please Selection"<?php echo  set_select('gender', 'Please Selection', TRUE); ?>>Please Selection</option>
         <?php /*?><option value="Other"<?php echo  set_select('gender', 'Other', TRUE); ?>>Other</option><?php */?>
      </select></label></div><span class="error"><?php echo form_error('gender')?></span></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label for="pAddress"></label>
      <input type="text" name="pAddress" id="pAddress" placeholder="Permanent Address" class='input-row' value="<?php echo set_value('pAddress')?>"/><span class="required"><?php echo form_error('pAddress');?></span></td>
      <td><label for="cAddress"></label>
      <input type="text" name="cAddress" id="cAddress" placeholder="Contact Address" value="<?php echo set_value('cAddress')?>"/><span class="required"><?php echo form_error('cAddress');?></span></td>
      <td>&nbsp;</td>
    </tr> 
    <tr>
      <td>Attach Your CV</td>
      <td colspan="2"><label for="cv"></label>
      <input type="file" name="cv" id="cv" value="<?php echo set_value('cv')?>"/><span class="error"><?php echo form_error('cv')?></span></td>
    </tr>
    <tr>

      <td><input type="submit" name="submit" id="submit" value="Submit" class="Button" />

        <input type="reset" name="reset" id="reset" value="Reset" class="Button" /></td>

      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form >

请出示您的控制器,您是否有错误?没有错误,但在提交不完整的表格后未设置上传文件的名称。但设置值是在输入类型textinput type=text上工作的。您能显示控制器吗?出于安全目的,您不能。想象一个浏览器正在抓取您的文件系统。您可以使用其他变通方法在文本字段中重新填充项名称。