I am attempting to use fopen() to allow me to pass values from csv cells to an Oracle 11g Database.
The csv was 'created' when a user uploads an xls via a html form. From there, I converted 'file.xls' to 'file.csv'. Up to this part, I have been successful. However, upon using fopen() [line 33, it is marked in notes], it fails to find the obviously created 'file.csv'. Is my notation wrong for using fopen()?
handler:
$allowed = array('xls');
$filename = $_FILES['uploaded']['name'];
$file = $_FILES['uploaded']['tmp_name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(in_array($ext,$allowed) ) {
$inputFileType = 'Excel5';
$inputFileName = $file;
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcelReader = $objReader->load($inputFileName);
$loadedSheetNames = $objPHPExcelReader->getSheetNames();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$objWriter->setSheetIndex($sheetIndex);
$objWriter->save('file'.'.csv');}
}
$fopen = fopen('file.csv', 'r'); //**line 33**//
if($fopen) {
while (($line = fgetcsv($files)) !== FALSE) {
$csv_array[] = array_combine(range(1, count($line)), array_values($line));
}
}
It may be nice to note that I do plan on adding a delete section to delete 'file.csv'. I am only using it to update the database, then it is useless to me. So, if there is a more efficient way than saving it, updating db, deleting it, I would love to know :). Thanks, SO community!