php - Warning with, fopen, feof and fgetcsv -
i'm in trouble, failing understand why error happening.
so when run code,
function getclientproject($cliente) { $file = fopen("projetos.csv","r"); $arraycount = 0; $bool = false; while(! feof($file)) { $data = fgetcsv($file); if($data[0] != '') { if(substr_compare($data[0],$cliente, 0, 3) == 0) { if($arraycount > 0) { $total = count($openproject); for($i=0;$i<$total;$i++) { if($openproject[$i] == $data[0]) $bool = true; } if($bool == false) { $openproject[$arraycount] = $data[0]; $arraycount++; } }else { $openproject[$arraycount] = $data[0]; $arraycount++; } } } } fclose($file); return $openproject; }
it works , returns array. when call function way,
include_once 'crm files/tsread.php'; $arrayc = getclientproject('sla'); var_dump($arrayc);
no longer works , me these errors,
what doing wrong?
path, file i'm using "projeto.php":
and crm files folder:
you opening file using relative path. assume projetos.csv
in same directory tsread.php
file. although, when including it, seem in higher directory (outside of crm files directory), therefor php can no longer find csv file, since it's trying open relative upper directory now.
you pass full path getclientproject
method avoid this. so, like:
$arrayc = getclientproject('sla', __dir__ . '/crm files/projectos.csv');
obviously, need change function little work new constructor, should this:
function getclientproject($cliente, $csv) { $file = fopen($csv, "r"); // followed rest of function
Comments
Post a Comment