Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: Creating an Upload Function For an Options Page?

  1. #21
    rzen's Avatar
    rzen is offline Hello World
    Join Date
    May 2010
    Location
    Grandville, MI
    Posts
    13

    Default

    I don't think so. It's especially odd because the upload does succeed, and when I go back to the options page and refresh the file is there.
    -Brian

  2. #22
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    865

    Default

    Could be something specific to 3.0? I see the ms.php, that's the multi-site thing. Might be something I didn't account for there.

  3. #23
    andrea_r's Avatar
    andrea_r is offline WordPress Rockstar
    Join Date
    Jan 2009
    Location
    Eastern Canada
    Posts
    1,325

    Default

    There's some new limits set in there with a check for a few variables including - upload size in php.ini, upload space in the blog itself and... some I forget. It checks them all and goes with the least.

    That explains why it's suddenly doing that, as wpmuguru rolled that in recently.

    As to why it;s failing for you, I dunno. I could holler at him to come look tho.

  4. #24
    rzen's Avatar
    rzen is offline Hello World
    Join Date
    May 2010
    Location
    Grandville, MI
    Posts
    13

    Default

    I've been running this on the 3.0 beta the whole time, so I'm not sure why it worked fine before and doesn't now. Did this change between beta 1 and beta 2?

    [edit]

    So, it's started working once more just as mysteriously as it had stopped. Here's my current validation:

    PHP Code:
    function sb_upload_validate($input) {
        
    $options get_option(THEME_PREFIX.'admin_logo_img');
        
    $newinput = array();
        if (
    $_FILES[THEME_PREFIX.'admin_logo_img']['name']) {
            
    $file wp_handle_upload($_FILES[THEME_PREFIX.'admin_logo_img'], array('test_form' => false));
            
    $newinput $file;
        } elseif {
            
    $newinput $options;
        }
        return 
    $newinput;

    Is there a way I could make this into a universal validator for any upload field? I'm sure it must be possible, but handling uploads via PHP is entirely new territory for me. Off the top of my head I would guess I could leverage the $input variable as $input['name'], but I'm afraid to test anything with this function now that it's working :)

    [edit 2]
    Premature celebration, the uploads still fail intermittently.

    Played around with error reporting and finally have something useful, "Specified file failed upload test". Much googling has turned up that this is a fairly common issue, but with zero solutions to be found. Most suggestions point to a permissions error, I don't think that is it. Anyone else have suggestions?

    The file only fails when it is the first attempted upload, after that every successive upload succeeds. By that I mean, if i use delete_option() to clear the setting and try an upload again, it fails once, after that every upload succeeds.
    Last edited by rzen; 05-22-2010 at 10:50 AM.
    -Brian

  5. #25
    wpmuguru is offline Here For The Peanuts
    Join Date
    Sep 2009
    Posts
    133

    Default

    In MU & in a 3.0 network, each blog/site has an media space quota (a global setting and potential individual override). If you are running a network before the file is moved to the site's media space, WP verifies that the file won't put the site over it's quota (that's why you are seeing ms.php).

    If you are unlinking (ie. deleting) the file before that check is done, you would get the error you are describing. There is a way to disable the upload space check. Look through ms.php for the upload related functions to find it ('cause I don't remember it off the top of my head).

  6. #26
    rzen's Avatar
    rzen is offline Hello World
    Join Date
    May 2010
    Location
    Grandville, MI
    Posts
    13

    Default

    I set both test_upload and test_size to false and still hit the same problem. Locally it's a WP error where it cannot move the file to the final uploads dir, but remotely it's the PHP error with filesize().

    It's most curious because the upload only fails on the very first attempt, every successive attempt works perfectly fine. I'm using delete_option() to clear out the stored image each time to reset my test. Could it be that the error is actually in updating the non-existant setting on the first try, and it's resolved because the second (and all others) have a pre-existing setting to update?
    -Brian

  7. #27
    kav
    kav is offline Hello World
    Join Date
    Aug 2010
    Posts
    1

    Default

    Thanks to Otto & Rzen, i got upload working. but i am not sure how to get multiple images uploaded(different images, not simultaneously). The array produced has three keys -> file, url and type.

    I am using a dynamic css file generated from theme_options and extract function to assign keys to variables.Alternatively, if i try to flatten the arrays, since two inner (upload) arrays have same key names, they get overwritten.
    Is it possible to rename the array keys?

  8. #28
    jneumann is offline Hello World
    Join Date
    Mar 2011
    Posts
    3

    Default

    I'm having a helluva time using mfields scripts. I can get the images to upload, but I can't for the life of me figure out how to get them into my theme. Any help would be appreciated.

  9. #29
    mfields's Avatar
    mfields is offline Here For The Peanuts
    Join Date
    Nov 2009
    Location
    Portland, OR
    Posts
    168

    Default

    Sorry to hear that ... To be absolutely honest with you, I would definitely approach this situation much differently now. I posted that code about a year and a half ago :) If your looking to use the WordPress media uploader in a plugin, you might want to check out my taxonomy images plugin on Github. It's far from perfect, but it get's the job done in *most* use cases. I've commented the code pretty well and the code is much more up-to-date.

  10. #30
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    865

    Default

    Coming back to this since I had a need for this code today, I'm looking at wp_handle_upload and I see that it handles errors itself. Here's how you check for errors properly.

    PHP Code:
    $overrides = array('test_form' => false);
    $file wp_handle_upload($_FILES['whatever'], $overrides);

    if ( isset(
    $file['error']) ) {
        
    // take proper action for the error

    The contents of $file['error'] will be a string that describes the error, so you can output that as appropriate.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •