0

I have this code copied from http://php.net/manual/es/features.file-upload.post-method.php and I tried it today, but I can't upload files.

Notice: Undefined index: file in C:\xampp\htdocs\kappa.php on line 13

Notice: Undefined index: file in C:\xampp\htdocs\kappa.php on line 16

¡Posible ataque de subida de ficheros!

Code:

<?php
if (isset($_POST['btn'])){
    $dir_subida = '';
    $fichero_subido = $dir_subida . basename($_FILES['fichero_usuario']['name']);

    echo '<pre>';
        if (move_uploaded_file($_FILES['file']['tmp_name'], $fichero_subido)) {
            echo "El fichero es válido y se subió con éxito.\n";
        } else {
            echo "¡Posible ataque de subida de ficheros!\n";
        }  
 }
 ?>

 <html>
 <head>
 </head>
 <body>
 <form action="" method="post">
     <input type="file" name="file">
     <input type="submit" name="btn">
 </form>
 </body>
 </html>

I tried to use diferent scripts, but it keeps throwing the same error.

I always have access to the path and all that stuff.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136

2 Answers2

1

When you want to upload a file, <form> has to have enctype attribute.

<form method="post" enctype='multipart/form-data'>
pavel
  • 26,538
  • 10
  • 45
  • 61
0

set attribute enctype="multipart/form-data" where it specifies which content-type to use when submitting the form.

Faesal
  • 679
  • 6
  • 19