Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Retrieve file informations with file handler
  • Hey guys,
    Can explain me how to retrieve file informations like extension, mime, ... Using file handler? Cheers
  • Grrr... Why is it always IE that f***s things up? I'll have a look later today...
  • Totally agree about IE. Chome is also a bit of a pain with downloads, because it won't give the user a choice to open or save. The headers I have for both IE and non-IE. will give the user a choice to open or save in both IE9 and Firefox 4/5. For example, the current headers in File::download will automatically open a jpg or graphic file in the browser. It will also automatically open a pdf if you have a pdf viewer.
  • Implemented some improvements. I've got no issues here with FF3/4, IE7/8 and Chrome. For Chrome, you can enable the prompt for a 'save as' in the preferences so it gives you a popup as well.
  • Yeah, that's much better. Thanks.
  • You don't. You use pathinfo() to get file name related information, and fileinfo() to get file content related information.
  • Ok ... as I thought.
    I wanted be sure on that. Thank you!
  • Yeah, no point in building in features that are readily available in plain PHP...
  • Haha you're right ... :)
  • Actually I'm not sure if I agree here. The file class is in part about creating a more logical interface to PHP's web of inconsistent and not always logical named functions/methods. This might be worthwhile addition, though I'd have to see an example of exactly what you want it to do before I'm sure.
  • I haven't a "real life" code on this ... but an example can be retrieve informations of files for build a complete Media manager. So, if I want create a table for all uploaded files, showing informations like :
    - File name
    - File Extension
    - File type
    - Mimetype
    - Size
    - File path I thought there was a function like
    File::info() -> return an array with all informations (mime, size, ...)
    File::info('size') -> return only file size but it's just a personal impression...
  • On second thought, maybe we have to come up with something clever here. fileinfo() has issues on Windows, and needs custom configuration on lots of Linux platforms as well. The Upload class currently uses fileinfo() as well, so centralizing this functionality in the File class might not be a bad idea.
  • I've tried to create a "protoype" for File::get_info() method like this http://scrp.at/4N What do you think about that?
  • Too late. :) I'm about to commit the update to the file class (including a fileinfo() and download() method).
  • Just pushed the commits to the develop branch. Docs are updated too. Is this sufficient?
  • You can't do better!! :-D
  • That's some fast work! Thanks. I just did a little testing of the File::download() function in FF 4.0.1 and IE 9.0.1. Firefox works pretty well, but I get a strange result when I try to download a Word doc with IE. First, it asks for a security login which I've never seen before. If I cancel the login, it will still download and open the Word file. However, I'm downloading the file from an admin section that requires a login. After the Word doc downloads, I'm then logged out. I also see about 16 additional entries in the sessions database table with user agent referring to Microsoft. (I cleared the table, so I don't have the exact user agent string.) I went back to some older websites not using the Fuel download and was able to download the Word doc with IE with no problem. So as a test, I replaced the headers that are set in the File::download() function with the headers I've been using for a while in my CI projects, and I had better results. The Word doc opened with no problem in IE, and also all of the downloads ask if I want to open or save. Fuel:download() headers:
      header('Content-type: '.$mime);
      header('Content-disposition: filename="'.$name.'"');
      header('Content-length: '.$info['size']);
      header('Cache-control: private');
    

    Headers I've been using for a while.
     if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
      {
       header('Content-Type: "' . $mime . '"');
       header('Content-Disposition: attachment; filename="' . $name . '"');
       header('Expires: 0');
       header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
       header("Content-Transfer-Encoding: binary");
       header('Pragma: public');
       header("Content-Length: " . $info['size']);
      }
      else
      {
       header('Content-Type: "' . $mime . '"');
       header('Content-Disposition: attachment; filename="' . $name . '"');
       header("Content-Transfer-Encoding: binary");
       header('Expires: 0');
       header('Pragma: no-cache');
       header("Content-Length: " . $info['size']);
      }
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion