[wp-hackers] wp_handle_upload
Andy Charrington
andycharrington at gmail.com
Tue Mar 22 11:05:00 UTC 2011
Hello,
I have a form that generates new file inputs on a user click. The form is
huge but in essence all that is relevant is this-
<form>
<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="file" name="image[]">
<input type="submit" name="submit" value="submit">
</form>
When the form is posted i would like to use wp_handle_upload.
I successfully use this when there are single files being uploaded but
cannot get it to work for an array.
Currently i have this-
$overrides = array('test_form' =>
false);
foreach($_FILES['image'][name] as $key => $value){
$file = wp_handle_upload($_FILES['image'], $overrides);
echo "<pre>"; print_r($file); echo "</pre>";
}
I know that is wrong but i cant figure out how to pass in each file in the
$_FILES array as the structure of the array is
Array
(
[albumimage] => Array
(
[name] => Array
(
[0] =>
[1] => cameron.jpg
[2] => clegg.jpg
)
[type] => Array
(
[0] =>
[1] => image/jpeg
[2] => image/jpeg
)
[tmp_name] => Array
(
[0] =>
[1] => /tmp/phpClmUp1
[2] => /tmp/php7p3TJO
)
[error] => Array
(
[0] => 4
[1] => 0
[2] => 0
)
[size] => Array
(
[0] => 0
[1] => 16165
[2] => 19181
)
)
)
I have looked at the wp_handle_upload function in wp-admin/includes/file.php
and can see where the function moves the file -
rename( $file['tmp_name'], $new_file )
But i need it to handle it like this-
foreach($file['tmp_name'] as $fileSingle){
rename( $file['tmp_name'][$i], $new_file )
}
or similar..... you can see what i mean....
Has anyone had experience with this? I would prefer to use wp_handle_upload
but am thinking i may have to resort to doing it manually...
If this is not possible is it something that needs a patch?
Any help massively appreciated!
Thank you!
Andy
--
Jealous Designs
Website: <http://jealousdesigns.co.uk/>jealousdesigns.co.uk
Portfolio: <http://jealousdesigns.co.uk/portfolio>
jealousdesigns.co.uk/portfolio
Phone: 07903030008
Twitter: _a_n_d_y
Skype: andycharrington
Web design | Web development | WordPress | Flash | Posters, business cards
and flyers | Bespoke online tools | PHP | MySQL | (X)HTML | CSS | Javascript
| ActionScript
More information about the wp-hackers
mailing list