Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Une fonction helper pour gérer l'upload et la création du media attachment
- */
- function msk_insert_attachment($file_handler, $id) {
- if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
- require_once(ABSPATH . "wp-admin" . '/includes/image.php');
- require_once(ABSPATH . "wp-admin" . '/includes/file.php');
- require_once(ABSPATH . "wp-admin" . '/includes/media.php');
- $attach_id = media_handle_upload($file_handler, $id);
- return $attach_id;
- }
- /*
- * Le traitement des input[type=file] (multiple upload de fichiers possibles)
- * Dans le formulaire il faut : <input type="file" name="fileupload[]" id="fileupload" multiple />
- */
- if ($_FILES) {
- $files = $_FILES['fileupload'];
- foreach ($files['name'] as $key => $value) {
- if ($files['name'][$key]) {
- $file = array(
- 'name' => $files['name'][$key],
- 'type' => $files['type'][$key],
- 'tmp_name' => $files['tmp_name'][$key],
- 'error' => $files['error'][$key],
- 'size' => $files['size'][$key]
- );
- $_FILES = array('upload_attachment' => $file);
- foreach ($_FILES as $file => $array) {
- $new_upload = msk_insert_attachment($file, $product_name_draft_id);
- $new_array = get_post_meta($product_name_draft_id, '_images_image', true);
- $new_array[] = $new_upload;
- update_post_meta($product_name_draft_id, '_images_image', $new_array);
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement