php does not recognize the file field

Asked

Viewed 513 times

1

So guys I’m working on a support system where has a form for the user to send the message where he selects the area, type the title the message and also a to send files if necessary the problem is that PHP does not recognize the field <input type="file" name="anexo_msg" />, when I give a <?php echo $_POST['anexo_msg'] ?> in the field PHP returns the following error: print do erro

Follow the HTML code of the page:

<h3>Clientes</h3>
      <?php echo "<p>".anchor("area_suporte", "<i class='icon-circle-arrow-left'></i> Voltar", array("class"=>"btn btn-small"))."</p>"; ?>

      <?php echo form_open_multipart(current_url(), 'class="form-horizontal"'); ?>
        <div class="control-group">
          <label class="control-label">Área</label>
          <div class="controls">
            <select name="i_area" class="input-large">
            <option value="" selected="selected" disabled="disabled">Selecione uma Área</option>
            <?php 
                $query = $this->db->get('areas')->result_array();
                foreach ($query as $data) :
            ?>
                <option value="<?php echo $data['i_area']; ?>"><?php echo $data['nome']; ?></option>
            <?php 
                endforeach;
            ?>
            </select>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label">Título</label>
          <div class="controls">
            <?php echo form_input('titulo', set_value('titulo'), 'class="input-xlarge" placeholder="Digite um Título"'); ?>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label">Descrição</label>
          <div class="controls">
            <?php echo form_textarea('descricao', set_value('descricao'), 'class="input-xxlarge" rows="10" placeholder="Mensagem que será enviada e lida pelo técnico"'); ?>
          </div>
        </div>
      <div class="control-group">
          <label class="control-label">Arquivo</label>
          <div class="controls">
            <?php echo form_upload('anexo_msg'); ?>
          </div>
        </div>
        <div class="control-group">
          <div class="controls">
        <?php 
            echo validation_errors('<p class="text-error">', '</p>'); 
            if ($this->session->flashdata('msgok') != "")
            {
                echo '<p class="text-success">'.$this->session->flashdata('msgok').'</p>';
            }
        ?>
            <button type="submit" class="btn btn-primary">Enviar ao Suporte</button>
          </div>
        </div>
        <?php echo $_POST['anexo_msg'] ?>
      <?php echo form_close(); ?>

OBS: I’m using Codeigniter

1 answer

3

Because it’s not $_POST['anexo_msg'] and yes $_FILES['anexo_msg'] and to see what’s inside you can make a var_dump($_FILES['anexo_msg']).

To see the file fields you can do so:

$file_name = $_FILES['anexo_msg']['name'];     //nome do ficheiro
$file_tmp  = $_FILES['anexo_msg']['tmp_name']; //caminho temporário para o ficheiro
$fileType  = $_FILES['anexo_msg']['type'];     //tipo do ficheiro
$file_size = $_FILES['anexo_msg']['size'];     //tamanho do ficheiro
$file_erro = $_FILES['anexo_msg']['error'];    //UPLOAD_ERR_OK = 0

To save the file on the server you can do:

$destino = '/home/user_name/data/'.$file_name;
move_uploaded_file($file_tmp,$destino);
  • 1

    Vlw guy helped a lot, more when I try to retrieve field content using codeigniter function <?php echo $this->input->post('anexo_msg'); ?> simply returns empty

  • 1

    I don’t understand that, but check out this answer: http://stackoverflow.com/a/10818235/1817673

Browser other questions tagged

You are not signed in. Login or sign up in order to post.