function fup_upload_action() { global $action, $fup_key; if ($action == 'upload') { if (!is_array($_FILES['image']['error'])) { return; } global $from_tab, $post_id, $style; if (!$from_tab) { $from_tab = 'upload'; } check_admin_referer('inlineuploading'); global $post_id, $post_title, $post_content; if (!current_user_can('upload_files')) { wp_die(__('You are not allowed to upload files.', 'fup') . " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=" . attribute_escape($style . "&tab=browse-all&post_id={$post_id}") . "'>" . __('Browse Files', 'fup') . '</a>'); } $overrides = array('action' => 'upload'); $errors = array(); $successed = array(); foreach ($_FILES['image']['error'] as $key => $value) { if ($value == 4) { $errors[] = "File {$key}(" . wp_specialchars($_FILES['image']['name'][$key]) . "): " . __("No file was uploaded.", 'fup'); continue; } $the_file = array('name' => $_FILES['image']['name'][$key], 'type' => $_FILES['image']['type'][$key], 'tmp_name' => $_FILES['image']['tmp_name'][$key], 'error' => $_FILES['image']['error'][$key], 'size' => $_FILES['image']['size'][$key]); $file = wp_handle_upload($the_file, $overrides); if (isset($file['error'])) { $errors[] = "File {$key}: " . $file['error']; continue; } $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename($file); // Construct the attachment array $attachment = array('post_title' => $post_title[$key] ? $post_title[$key] : $filename, 'post_content' => $post_content[$key], 'post_type' => 'attachment', 'post_parent' => $post_id, 'post_mime_type' => $type, 'guid' => $url); $fup_key = $key; // Resize image and create thumbnail if applicable fup_resize_and_thumbnail($file); // Save the data $id = wp_insert_attachment($attachment, $file, $post_id); wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file)); $successed[] = $filename; } if (empty($successed)) { wp_die(implode('<br />', $errors) . "<br /><a href='" . get_option('siteurl') . "/wp-admin/upload.php?style={$style}&tab={$from_tab}&post_id={$post_id}'>" . __('Back to Image Uploading', 'fup') . '</a>'); } if (count($successed) > 1) { wp_redirect(get_option('siteurl') . "/wp-admin/upload.php?style={$style}&tab=browse&post_id={$post_id}"); } else { wp_redirect(get_option('siteurl') . "/wp-admin/upload.php?style={$style}&tab=browse&action=view&ID={$id}&post_id={$post_id}"); } die; } }
$overrides = array('action' => 'save'); $file = wp_handle_upload($_FILES['image'], $overrides); if (isset($file['error'])) { die($file['error'] . '<br /><a href="' . basename(__FILE__) . '?action=upload&post=' . $post . '">' . __('Back to Image Uploading', 'fup') . '</a>'); } $url = $file['url']; $type = $file['type']; $file = $file['file']; $filename = basename($file); // Construct the attachment array $attachment = array('post_title' => $imgtitle ? $imgtitle : $filename, 'post_content' => $descr, 'post_status' => 'attachment', 'post_parent' => $post, 'post_mime_type' => $type, 'guid' => $url); // Save the data $id = wp_insert_attachment($attachment, $file, $post); if (preg_match('!^image/!', $attachment['post_mime_type'])) { // Resize, create thumbnail & incrust watermark (if needed) fup_resize_and_thumbnail($file); // Generate the attachment's postmeta. $imagesize = getimagesize($file); $imagedata['width'] = $imagesize['0']; $imagedata['height'] = $imagesize['1']; list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); $imagedata['hwstring_small'] = "height='{$uheight}' width='{$uwidth}'"; $imagedata['file'] = $file; // Update and save attachment metadata $imagedata = fup_update_attachment_metadata($imagedata); add_post_meta($id, '_wp_attachment_metadata', $imagedata); } else { add_post_meta($id, '_wp_attachment_metadata', array()); } wp_redirect(basename(__FILE__) . "?post={$post}&all={$all}&action=view&start=0"); die;