Load of CSV Centos 7 PHP problems

0

Hi, I have a CSV file that contains this configuration:

if (isset($_POST['submit'])) {
$allowed = array('csv');
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if (!in_array($ext, $allowed)) {
    $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 documento
     FIELDS TERMINATED BY ';'
     LINES TERMINATED BY '\r\n'
     IGNORE 1 LINES
    (titulo_documento,proyecto,estado,idioma,num_documento,version,revision,descripcion,fecha,subcategoria,confidencialidad,tipo_documento,acro_usuario,aprobado_por,autorizado_por,revisor,compania,codigo_proyecto)
eof;
    if (!$result = mysqli_query($con, $query)) {
        exit(mysqli_error($con));
    }
    $message = "CSV importado correctamente!";
}
}

And I have these permissions on the Centos Server in the "files /" folder

drwxrwxrwx. 2 apache apache  4096 jul 21 10:34 files

And if I try all this in a "Xampp" local Windows works perfectly, if not the file uploads and then loads and here in Centos 7 tells me:

Can't find file 'files/Documento2.csv'.
    
asked by Alberto Cepero de Andrés 21.07.2017 в 12:49
source

1 answer

1

I think the problem is permissions, how do you have that Apache server configured?

I see that you have the user apache:apache that I understand that you do it to be able to run PHP through the Apache server.

The best thing you can do is set PHP-FPM so that it is the same user you are using to "search" and execute PHP , and the one you use as shell

Here is a simple manual on how to install PHP-FPM at Centos6 and Centos7

If once you have the correct permissions, it keeps giving you errors, you tell me about it and we look at other alternatives.

    
answered by 28.07.2017 / 09:24
source