I've a problem with a PHP script that creates some csv file. The PHP script is the following:
<?php
$inputFile = "/var/www/vhosts/pecso.it/httpdocs/test/export30gg.txt";
$csvData = file_get_contents($inputFile);
$rows = explode(PHP_EOL, $csvData);
$rowsArray = array();
foreach ($rows as $row) {
$rowsArray[] = str_getcsv($row);
}
$csvFileName = "/var/www/vhosts/pecso.it/httpdocs/graphs/export30gg.csv";
if (file_exists($csvFileName)){
unlink($csvFileName);
}
$csvFile = fopen($csvFileName, "w");
$csvFileForGraph = fopen($csvFileNameForGraph, "w");
for ($i = 0; $i < count($rowsArray); $i++) {
$dateTime = DateTime::createFromFormat('d/m/Y', $rowsArray[$i][0]);
$d = $dateTime->format('Y-m-d');
$rowsArray[$i][0] = $d;
$rowForGraph = $rowsArray[$i];
unset($rowForGraph[1]);
$row = implode(',',$rowsArray[$i]);
$rowForGraph = implode(',',$rowForGraph);
file_put_contents($csvFileName, $row.PHP_EOL , FILE_APPEND);
}
fclose($csvFileName);
?>
This script works correctly and csv file export30gg.csv is correctly created but, every time I run this script, I've the following error:
fclose() expects parameter 1 to be resource
Can you help me, please?