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.
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
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.
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.
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:
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 :)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;
}
[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
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).
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
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?
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.
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.
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.
The contents of $file['error'] will be a string that describes the error, so you can output that as appropriate.PHP Code:$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES['whatever'], $overrides);
if ( isset($file['error']) ) {
// take proper action for the error
}