File upload with PHP

0

I do not understand very well why an input type file in a form does not work for me. Can you help me find the error?

Form :

<input type="file" name="imagen" class="form-control">

Processed :

<?php
    $codigo = $_POST["codigo"];
    if (is_uploaded_file ($_FILES['imagen']['tmp_name'])) {
        $nombreDirectorio = "img/";
        $nombreFichero = $codigo;
        $nombreCompleto = $nombreDirectorio . $nombreFichero;
        move_uploaded_file ($_FILES['imagen']['tmp_name'],
        $nombreCompleto);
        echo "Añadida con éxito";
    } else {
        echo "Error al subir imagen";
    }               
?>  

I have also made Apache the owner of the files and folders of the web application so that it had all the permissions.

    
asked by Cricket 27.01.2017 в 11:06
source

1 answer

5

You must check that your form has the attribute enctype="multipart/form-data"

<form enctype="multipart/form-data" method="post">
  <input type="file" name="file" />
</form>
    
answered by 27.01.2017 в 11:46