SaldaVonSchwartz
SaldaVonSchwartz

Reputation: 3809

PHPExcel reader doesn't seem to be reading in file?

I'm trying to open an xlsx file to parse it into an sqlite3 db. But I don't seem to be able to even open the xlsx file.

This is my code:

<?php

  require_once 'Classes/PHPExcel.php';
  require_once 'Classes/PHPExcel/IOFactory.php';

  error_reporting(E_ALL);

  print "trying to upload";

  $fileName = basename($_FILES['uploadedfile']['name']);
  $target_path = "someDir/";
  $target_path .= $fileName;

  if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
  {
    print "Upload Successful";  
    chmod($fileName, 0644);

    $objReader = new PHPExcel_Reader_Excel2007(); 
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($fileName);

    print "still online!";
  }
?>

but the script doesn't make it to the last print statement. So somewhere things are getting messed up in those 4 calls to the PHPExcel API. But no errors are reported.

Any thoughts?

Upvotes: 2

Views: 3339

Answers (1)

Andy
Andy

Reputation: 110

You seem to be trying to load the file relative to the script path, but you've actually moved it to another directory. So change this line:

$objPHPExcel = $objReader->load($fileName);

to:

$objPHPExcel = $objReader->load($target_path);

which would be the full path, eg, 'someDir/filename.xlsx'.

You'll want to change your chmod call to use $target_path as well, as it's unlikely it is finding the file to modify the permissions (it'll just return false if not).

Upvotes: 2

Related Questions