2014-07-03 14:23
浏览 72


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()?


$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) {

    $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!

图片转代码服务由CSDN问答提供 功能建议

我试图使用fopen()允许我将值从csv单元传递到Oracle 11g数据库。 / p>

当用户通过html表单上传xls时,csv已“创建”。 从那里,我将'file.xls'转换为'file.csv'。 到目前为止,我已经取得了成功。 但是,在使用fopen()[第33行,它在注释中标记]时,它无法找到明显创建的'file.csv'。 使用fopen()?


  $ 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');  // **第33行** // n如果($ fopen){
 while(($ line = fgetcsv($ files))!== FALSE){
 $ csv_array [] = array_combine(范围(1)  ,count($ line)),array_values($ line)); 

值得注意的是我确实计划添加 删除“file.csv”的删除部分。 我只是用它来更新数据库,那对我来说没用。 所以,如果有一种比保存它更有效的方法,更新数据库,删除它,我很想知道:)。 谢谢,SO社区!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doushangan3690 2014-07-03 14:37

    It all depends on where $objWriter->save() will save the file. If that is the same folder as the input file then it will be your temporary directory (/tmp/ most likely on *nix) And it is not likely that open() will look there by default.

    You can avoid these problems my making all paths absolute.

    打赏 评论

相关推荐 更多相似问题