IOFactory for TEMP files (with the *.tmp extension) ??

Topics: Developer Forum
Aug 17, 2012 at 12:32 AM
Edited Aug 17, 2012 at 12:35 AM

The auto-detecting is working great when it can read the file extension, but how can I get it to play nice when the file has a *.tmp extension ?

Here's the whole picture. 

We don't need to store our spreadsheets long term and the file will be uploaded via a form, so the temp location suites me just fine ... but when stored in the temp dir, the file has a ".tmp" extension.

We can easily get the original extension of the file via pathinfo().

What is the most maintainable (ie: easiest :) way to select the appropriate Reader with only the file extension?

Also, I'm totally open to other ideas and suggestions.


Aug 17, 2012 at 1:00 AM

Using autodetection identify() method in the IOFactory, should work regardless. It only uses the file extension for its initial guess as to the most appropriate reader to use. If that fails, then it will still try all the other readers until it finds one that seems to work... the main failing is that the CSV reader will act as a fallback because almost any file can be read as a csv (I'm looking at ways in which csv can be properly detected so that it can drop through to throw an exception).

Basing any logic purely on the file extension isn't a good option (at least not from the perspective of the library) because so many people use an .xls extension for all manner of file types that aren't actually BIFF files. If you're working in a closed environment where you can guarantee that .xls really means a BIFF format Excel file rather than html markup, then you probably want to "steal" the basic "initial guess" logic from the IOFactory, and use that in your own code.

Aug 17, 2012 at 1:50 PM