Load of CSV erroneous

0

In this code I have a small example of how to load CSV:

    $message = "";
if (isset($_POST['submit'])) {
$allowed = array('csv');
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed)) {
    // show error message
    $message = 'Archivo invalido, porfavor usa un archivo .CSV!';
} else {

    move_uploaded_file($_FILES["file"]["tmp_name"], "files/" . $_FILES['file']['name']);

    $file = "files/" . $_FILES['file']['name'];

    $query = <<<eof
    LOAD DATA LOCAL INFILE '$file'
     INTO TABLE proyectos
     FIELDS TERMINATED BY ';'
     LINES TERMINATED BY '\r\n'
     IGNORE 1 LINES
    (oferta_proyecto,acro_proyecto,nombre_proyecto,descripcion,compania)
eof;
    if (!$result = mysqli_query($con, $query)) {
        exit(mysqli_error($con));
    }
    $message = "CSV importado correctamente!";
}
 }

But as you see this only load from a specific site, and what I want is to remove it, for users to upload from anywhere:

This is the new code that tries

$ message="";     if (isset ($ _ POST ['submit'])) {     $ allowed = array ('csv');     $ filename = $ _FILES ['name'];

if (!in_array($ext, $allowed)) {
    // show error message
    $message = 'Archivo invalido, porfavor usa un archivo .CSV!';
} else {



    $query = <<<eof
    LOAD DATA LOCAL INFILE '$file'
     INTO TABLE proyectos
     FIELDS TERMINATED BY ';'
     LINES TERMINATED BY '\r\n'
     IGNORE 1 LINES
    (oferta_proyecto,acro_proyecto,nombre_proyecto,descripcion,compania)
eof;
    if (!$result = mysqli_query($con, $query)) {
        exit(mysqli_error($con));
    }
    $message = "CSV importado correctamente!";
}
}
    
asked by Alberto Cepero de Andrés 29.06.2017 в 09:13
source

0 answers