Changeset 5008
- Timestamp:
- 03/09/2007 08:14:52 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r4990 r5008 1095 1095 } 1096 1096 1097 function wp_upload_bits($name, $type, $bits , $overwrite = false) {1097 function wp_upload_bits($name, $type, $bits) { 1098 1098 if ( empty($name) ) 1099 1099 return array('error' => __("Empty filename")); … … 1123 1123 } 1124 1124 1125 // If we are asked to over write the file then make sure 1126 // the $name has the complete path and is writable. 1127 if($overwrite) { 1128 if(!is_writable($name)) { 1129 return(array("error" => __("Can not over write file."))); 1130 } 1131 $new_file = $name; 1132 $filename = basename($name); 1133 } 1134 else { 1135 $new_file = $upload['path'] . "/$filename"; 1136 if ( ! wp_mkdir_p( dirname($new_file) ) ) { 1137 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 1138 return array('error' => $message); 1139 } 1125 $new_file = $upload['path'] . "/$filename"; 1126 if ( ! wp_mkdir_p( dirname($new_file) ) ) { 1127 $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); 1128 return array('error' => $message); 1140 1129 } 1141 1130 … … 1152 1141 @ chmod($new_file, $perms); 1153 1142 1154 // Compute the URL if this is a new file.1143 // Compute the URL 1155 1144 $url = $upload['url'] . "/$filename"; 1156 if($overwrite) {1157 $url = $name;1158 }1159 1145 1160 1146 return array('file' => $new_file, 'url' => $url, 'error' => false); -
trunk/xmlrpc.php
r4961 r5008 1384 1384 $bits = $data['bits']; 1385 1385 1386 // Default to new file, not over write.1387 $overwrite = false;1388 1386 if(!empty($data["overwrite"]) && ($data["overwrite"] == true)) { 1389 $overwrite = true;1390 1391 // If the file isn't writable then error out now.1392 if(!is_writable($data["name"])) {1393 return(new IXR_Error(500, "File is not writable, over write failed."));1394 }1395 1396 // We now know the file is good so don't use the sanitized name.1397 $name = $data["name"];1398 1399 1387 // Get postmeta info on the object. 1400 $old_ meta= $wpdb->get_row("1401 SELECT *1402 FROM {$wpdb->post meta}1403 WHERE meta_key = '_wp_attached_file'1404 AND meta_value = '{$name}'1388 $old_file = $wpdb->get_row(" 1389 SELECT ID 1390 FROM {$wpdb->posts} 1391 WHERE post_title = '{$name}' 1392 AND post_type = 'attachment' 1405 1393 "); 1406 1394 1407 // Get post info on the object. 1408 $old_post = get_post($old_meta->post_id); 1395 // Delete previous file. 1396 wp_delete_attachment($old_file->ID); 1397 1398 // Make sure the new name is different by pre-pending the 1399 // previous post id. 1400 $filename = preg_replace("/^wpid\d+-/", "", $name); 1401 $name = "wpid{$old_file->ID}-{$filename}"; 1409 1402 } 1410 1403 … … 1441 1434 ); 1442 1435 1443 // If we are over writing then set the correct post_id and URL1444 // instead of getting new ones.1445 if($overwrite) {1446 $post_id = $old_meta->post_id;1447 $attachment["post_parent"] = $old_meta->post_id;1448 $attachment["ID"] = $old_meta->post_id;1449 1450 $upload["url"] = $old_post->guid;1451 $attachment["guid"] = $old_post->guid;1452 }1453 1454 1436 // Save the data 1455 1437 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id ); 1456 1438 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 1457 1439 1458 return apply_filters( 'wp_handle_upload', array( 'file' => $ upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );1440 return apply_filters( 'wp_handle_upload', array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type ) ); 1459 1441 } 1460 1442
Note: See TracChangeset
for help on using the changeset viewer.