Changeset 11944 for trunk/wp-admin/includes/media.php
- Timestamp:
- 09/17/2009 08:36:59 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r11911 r11944 250 250 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { 251 251 $overrides = array('test_form'=>false); 252 252 253 $file = wp_handle_sideload($file_array, $overrides); 253 254 254 if ( isset($file['error']) ) 255 255 return new WP_Error( 'upload_error', $file['error'] ); … … 280 280 ), $post_data ); 281 281 282 // Save the data282 // Save the attachment metadata 283 283 $id = wp_insert_attachment($attachment, $file, $post_id); 284 284 if ( !is_wp_error($id) ) { … … 521 521 function media_sideload_image($file, $post_id, $desc = null) { 522 522 if (!empty($file) ) { 523 $file_array['name'] = basename($file);523 // Download file to temp location 524 524 $tmp = download_url($file); 525 526 // Set variables for storage 527 // fix file filename for query strings 528 preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches); 529 $file_array['name'] = basename($matches[0]); 525 530 $file_array['tmp_name'] = $tmp; 526 $desc = @$desc; 527 531 532 // If error storing temporarily, unlink 528 533 if ( is_wp_error($tmp) ) { 529 534 @unlink($file_array['tmp_name']); 530 535 $file_array['tmp_name'] = ''; 531 536 } 532 533 $id = media_handle_sideload($file_array, $post_id, $desc); 537 538 // do the validation and storage stuff 539 $id = media_handle_sideload($file_array, $post_id, @$desc); 534 540 $src = $id; 535 541 542 // If error storing permanently, unlink 536 543 if ( is_wp_error($id) ) { 537 544 @unlink($file_array['tmp_name']); … … 539 546 } 540 547 } 541 548 549 // Finally check to make sure the file has been saved, then return the html 542 550 if ( !empty($src) ) { 543 551 $alt = @$desc;
Note: See TracChangeset
for help on using the changeset viewer.