ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Get metadata of uploaded files (file repository)

September 02, 2008 6:25am

Subscribe [3]
  • #1 / Sep 02, 2008 6:25am

    monopaul

    4 posts

    I looked a bit around in the forum, but there doesn’t seem to be a topic where this has been covered.

    I would like to build a file repository / download section for site visitors. The repository can easily be built using a weblog and custom fields to hold the link to the document.

    However, I was wondering if there is as way to

    (i) extract the file’s metadata, like size, what kind of document.

    (ii) replace the document links with icons according to their format(this can be done with css, but this would not work in IE, obviously…)

    Thanks a lot for all help.

  • #2 / Sep 02, 2008 6:35am

    Mark Bowen

    12637 posts

    Hiya,

    As regards to file-size this could be done in a number of ways. You could use some PHP to retrieve the information and print it to the page or you could use a plugin specifically for this job. There is one that I remember that Andy (ExpressionEngineer) made a while back called :

    Filesize

    That might help on that front.

    Now down to what a file is. Hmmm!

    If you are using standard extensions such as .pdf, .jpg, .doc and so on and so forth then you could just extract the extension from the end of the file and use some conditionals to say what the file is. You could probably also use some PHP magic, I think?

    Depends really on how many formats you are going to be using? If only a few then I would go with simple conditionals as that would be the easiest in my mind.

    Then as to the icons. Yep it’s a shame that IE doesn’t support selectors as it would be really easy then but coming back to what I said previously about how many file-types you are going to be supporting then if only a few again you could just extract the .jpg part and then use conditionals to display whatever image you desire.

    Don’t know if that helps at all.

    Best wishes,

    Mark

  • #3 / Sep 02, 2008 6:51am

    cherrypj

    158 posts

    Of course, Mark’s pretty dead on with his response.

    If you’re OK with doing this thing outside of EE/PHP, you might look at addSizes.js. It’s a small JS script that reads the headers of a file and extracts the file size. You can get the file type from the URL. The script could be modified to extract other information, since there’s quite a bit sent via the HTTP header.

    It does rely on Google’s AppEngine, so it’s apparently a little flaky.

    LG Better Meta might also be useful, especially if you use a weblog entry for each file.

  • #4 / Sep 02, 2008 7:19am

    monopaul

    4 posts

    Thanks a lot for your quick help. Awesome. I don’t really mind that such functionality is served outside of EE, be it by a javascript or some php script. I guess the number of file formats will be limited to the most common ones, like word, pdf, etc. I will look into the filesize plugin tonight.

    Seems like php will be the allround solution in this case.

    The LG better meta looks great too, not for this purpose, but bookmarked anyway.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases