php does not recognize the file field

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

FollowingtheHTMLofthepage:

<h3>Clientes</h3><?phpecho"<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(); ?>

I'm using CodeIgniter

    
asked by anonymous 01.04.2015 / 17:02

1 answer

3

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

To see the file fields you can do this:

$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 to the server you can do:

$destino = '/home/user_name/data/'.$file_name;
move_uploaded_file($file_tmp,$destino);
    
01.04.2015 / 17:05