I am trying to upload a CSV file and get it’s contents into an array, but I am getting this an error: (Multiples of this error on each line after 10)
Notice: Undefined offset: 1 in C:\xampp\htdocs\amazon\upload_file.php on line 10
Below is a sample of my code:
if ($handle = file_get_contents($_FILES["file"]["tmp_name"])) {
$data = array();
while ($csv = array(file_get_contents($_FILES["file"]["tmp_name"]))) {
$data = array(
'order-id' => $csv[0],
'order-item-id' => $csv[1], //This is line 10.
'purchase-date' => $csv[2],
'payments-date' => $csv[3],
file()opens puts each as an array element.fgetcsv()and its family of functions are very useful when dealing with csv files.Your code
array(file_get_contents($_FILES["file"]["tmp_name"]))will only ever have one element because file_get_contents returns a string.