canRead

Aug 21, 2009 at 2:36 PM

 

Hey Guys,
i try to check if the CSV File can be read and if it is really a csv file.
But the following code always returns boolen false.
What's my error? Do i have to do the $objReader->load() before?
Or why this check always fails?
And how can i check if its really a csv?
Please help me, i'm lost in the PHPExcel Jungle :-)
thank you Max

if
($objReader->canRead($_FILES[$this->name_dateiupload_feld]['tmp_name'])) {

 

Developer
Aug 21, 2009 at 3:51 PM

You have pointed out a bug in PHPExcel. Copying this to a work item:

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10498

For now, change this in Classes/PHPExcel/Reader/CSV.php

/**
     * Can the current PHPExcel_Reader_IReader read the file?
     *
     * @param     string         $pFileName
     * @return     boolean
     */    
    public function canRead($pFilename)
    {
        // Check if file exists
        if (!file_exists($pFilename)) {
            throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
        }
        
        // Check if it is a CSV file (using file name)
        return (substr(strtolower($pFilename), -3) == 'csv');
    }

to this until we have a solution.

/**
     * Can the current PHPExcel_Reader_IReader read the file?
     *
     * @param     string         $pFileName
     * @return     boolean
     */    
    public function canRead($pFilename)
    {
        // Check if file exists
        if (!file_exists($pFilename)) {
            throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
        }
        
        return true;
    }