File field

With the file field you can select a file from the media library, or upload a new file. The selected file is presented with a thumbnail and the title of the file. With this field type you can add images, PDFs, Word Documents, PowerPoints etc. to your posts.

Return value

The id of the selected file.

Extended Return Values

When enabled, return value will be an array will lots of useful info about the selected file. Example of output:


// Field slug is "fileExample"
$file_id = simple_fields_value('fileExample');
$image_info = wp_get_attachment_image_src($file_id, "full");
$image_url = $image_info[0];
$image_width = $image_info[1];
$image_height = $image_info[2];
echo "The uploaded image has a width of $image_width pixels and a height of $image_height pixels. The full URL to the image is $image_url";

Output of above

The uploaded image has a width of 200 pixels and a height of 286 pixels. The full URL to the image is http://localhost/wordpress/wp-content/uploads/cute-kitten.jpg

19 thoughts on “File field

  1. Rémi

    Hi Pär

    More for the serie “thoughts on “File field”

    In my previous comment I was asking for a solution to show the select tabs “media-toolbar-secondary”.

    I have read your comment in the js file “// TODO: how do i get the filter dropdown?? i think i’ve tried everything!” and I tried to understand a bit more, before asking for a solution. );

    First of all, your plugin is working correctly, and it is not a missing feature but the way wordpress designed the ‘select’ frame in the js backbone view.
    using the frame : ‘post’ do show the dropdowns

    other plugins are delivering the same view without tabs.
    this demol plugin helped me understand it.

    I had a look at the solution proposed here to add a backbone custom view:

    and after changing the code of the file ‘scripts.js’ (simple-fields Versión 1.4.5) between the lines 62 and 75, I can now open the media editor with a new view “myView” showing the dropdowns.

    // line 62 ———– Original code ———-
    // Code based on
    // TODO: how do i get the filter dropdown?? i think i’ve tried everything!
    my.media_frame ={
    className: ‘media-frame simple-fields-media-frame’,
    frame: ‘select’, // select | post. select removed left nav (insert media, create gallery, set featured image)
    multiple: false,
    title: _wpMediaViewsL10n.mediaLibraryTitle,
    /*library: {
    //type: ‘audio’ // image | audio
    button: {
    text: _wpMediaViewsL10n.insertIntoPost
    // line 75 ———– end original code ———-

    //———– replaced with the following: ———-
    my.media_frame ={
    state : ‘mystate’,
    className: ‘media-frame simple-fields-media-frame’,
    frame: ‘select’, // select | post. select removed left nav (insert media, create gallery, set featured image)
    multiple: false,
    title: _wpMediaViewsL10n.mediaLibraryTitle,
    /*library: {
    //type: ‘audio’ // image | audio
    button: {
    text: _wpMediaViewsL10n.insertIntoPost


    id: ‘mystate’,
    title: ‘myView’,
    priority: 2,
    toolbar: ‘select’,
    filterable: ‘uploaded’,
    library: my.media_frame.options.library ),
    multiple: my.media_frame.options.multiple ? ‘reset’ : true,
    editable: true,
    displayUserSettings: true,
    displaySettings: true,
    allowLocalEdits: true
    //AttachmentView: ?


    ———– end of hack ———-

    //your code follows on line 77 with:
    // my.media_frame.on(‘select’, function(){

    Once opened the media overlay, I can see the selects with my image categories created with the plugin “enhanced-media-library”.

    I still would have to remove the default library view, visible beside “myView” but I will need to dive deeper in the backbone reference.

    I hope it helps.


  2. Rémi

    Hi I also need the media-toolbar-secondary !
    I use the file input type for creating gallery on the fly, using repeatable fields, everything perfect, super easy to configure and use, but…
    the fact that I can not see my media_categories make the designed tool useless.
    I use “enhanced-media-library” to organize the media.

    Can you explain me how to add the “media-toolbar-secondary” ?

  3. mehkyle

    Hi, This plugin is great. But could you please tell me how I can output the URL(I’m using the file type field) and output the value of a text field at the same time?

  4. momper

    hi pär,

    we use the “file field” since wp 3.4 – erverythings works like a charm.
    now we updated to wp 3.5 and sf 1.2 and want to use the new media browser window together with some filters of the Media Library Assistant plugin. but we still get the old media browser window without this functionality. the editor related button uses “button insert-media add_media” as classes – the “file field” uses “simple-fields-metabox-field-file-select”. but to change only this has no success …
    have you got an idea? should this problem be solved in the current version?

    1. Pär Thernström Post author

      Hi! I haven’t tried the Media Library Assistant plugin, but I guess I hooks onto some things that apparently don’t work together with SF. Can you explain a bit further what works and what doesnt? You say for example that you get the old media browser. Do you mean the media browser that existed before 3.5 or do you mean the new browser, but without the enhancements made by Media Library Assistant?

      1. Bole

        Hello there, I think I have the same problem. I explain:

        When I use the uploadfield from the standars fields from WP with Media-library-assitants plugin it shows the media-browser like it is, but adding two dropdowns more after the “attachment-filters” in div class=”media-toolbar-secondary” and a custom searching box for media replacing the standard one. Those dropdown are “attachment-months” to sort by date and “attachment-terms” to add your media elements to categories previously created in the section from Media section.

        In the other hand, when I use Simplefields filefield to upload. It shows the mediabrowser in the same way like I described before but without “all” the dropdowns, event the default by WP, but the custom search box, added by Media-library, is showed propperly. Moreover the left column “media-frame-menu” is missing as well.

        Seems that there is a problem with the filling of the div class=”media-toolbar-secondary” that is empty and with the left column “media-frame-menu”.

  5. Greg Berger

    Is it on purpose that this field can’t automatically create attachements to the post with the file that has been uploaded?

    Do you think of any method that would do the trick?

    Nevertheless thanks for this useful plugin!

    1. Pär Thernström Post author

      @Greg: If you mean that an image/file is not considered “attached to” a post when you view the media file in the media page, then yes that’s on purpose. No one else has requested this – and I have never seen the need for it. If it’s very important for this to happen then perhaps I can add a setting for the file field to add all attached files attachments too!

      1. Greg Berger

        first of all thanks for your quick reply !
        Yes, I may say it is quite important to me as I need the image file to be an attachement to interact with another plugin (which I use for cropping images “on the fly”)

        I’m trying to figure a way out to attach the file by hooking to ‘save_post’ but i’m not really sure about the accuracy of this method.

        Maybe you’d have a better idea that would integrate better with your work (a hook i didn’t think of, or sth like this).

        Anyway thanks for your help

Leave a Reply