Upload Csv with php error: Undefined offset:

Asked

Viewed 73 times

0

good morning. I am uploading csv with php, the same does the processing but gives the following error: "Undefined offset:" I cannot identify this error and treat... Help me!..

  • Put your code so we can help

  • Follows the Code:

  • First Part: $arrFileName = explode('. ', $_FILES['file]['name']); if ($arrFileName[0] = 'csv') { $Handle = fopen($_FILES['file']['tmp_name'], "r"); fgetcsv($Handle);

  • second part: while (($data = fgetcsv($Handle, 1000, ";")) !== FALSE) { $WORKORDERUID = mysqli_real_escape_string($Conn, $data[0]);

  • the variable $date[0] goes up to the variable $date[19]

  • hence comes the import query, Select into....

  • You can edit your question and add code there, it is also good format it, thus becomes more readable. After making can delete the comments :)

Show 2 more comments

1 answer

0


The error of "Undefined offset" usually happens when you are trying to do some operation with the nonexistent value of an array.

In CSV (or excel) files sometimes comes empty rows and columns, which it understands as being part to file (even if it has no value at all). So before you perform explodes, or other operations, it is always good to test whether the array value actually exists:

if (isset($_FILES['file']['name']) && !empty($_FILES['file']['name'])) { [...] }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.