move_uploaded_file ()

0

Good day, I'm working with Xammp creating a API that loads files and I have this code:

$nomarchivo = $_FILES['file']['name'];
$tipoarchivo = $_FILES['file']['type'];
$tamano = $_FILES['file']['size'];
$uploadsdir = "*/files/";

if (($tipoarchivo === "application/pdf") && ($tamano < 1000000)) {
    move_uploaded_file($_FILES['file']['tmp_name'], $uploadsdir.$nomarchivo);
} else {
    echo "Solo se permiten archivos pdf y temaño menor a 125kb";
}

but gives these errors:

  

Warning: move_uploaded_file (* / files / Test.pdf): failed to open stream:   No error in C: \ xampp \ htdocs \ tests \ api \ uploadfile.php on line 12

     

Warning: move_uploaded_file (): Unable to move   'C: \ xampp \ tmp \ phpD852.tmp' to '* / files / Test.pdf' in   C: \ xampp \ htdocs \ tests \ api \ uploadfile.php on line 12

Try with% full% co to avoid the error but it does not work. What else can it be?

    
asked by Angel Rodriguez 01.04.2017 в 06:52
source

3 answers

0

The $uploadsdir does not seem right to the "result" of the path */files/ ; use relative or specific route.

It also verifies that the user under which the web server runs has permissions to the destination folder (the necessary permissions).

    
answered by 01.04.2017 в 07:15
0

The problem is in this line:

$uploadsdir = "*/files/";

It should go as follows:

$uploadsdir = "./files/";

or

$uploadsdir= "files/";
    
answered by 01.04.2017 в 08:35
0

I do it with the copy function, I do not know if it serves you well  $ upload_folder = '../ Invoices';

        $nombre_archivo = $_FILES['archivo']['name'];

        $tipo_archivo = $_FILES['archivo']['type'];

        $tamano_archivo = $_FILES['archivo']['size'];

        $tmp_archivo = $_FILES['archivo']['tmp_name'];

        $archivador = $upload_folder . '/' . $nombre_archivo;

        copy($tmp_archivo, $archivador);
    
answered by 01.04.2017 в 19:41