Change xmlrpc upload logic. Props Joseph Scott.

git-svn-id: https://develop.svn.wordpress.org/trunk@5008 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2007-03-09 20:14:52 +00:00
parent db67d51e29
commit c79783485f
2 changed files with 19 additions and 51 deletions
+6 -20
View File
@@ -1094,7 +1094,7 @@ function wp_upload_dir() {
return apply_filters('upload_dir', $uploads);
}
function wp_upload_bits($name, $type, $bits, $overwrite = false) {
function wp_upload_bits($name, $type, $bits) {
if ( empty($name) )
return array('error' => __("Empty filename"));
@@ -1122,21 +1122,10 @@ function wp_upload_bits($name, $type, $bits, $overwrite = false) {
$filename = str_replace("$number$ext", ++$number . $ext, $filename);
}
// If we are asked to over write the file then make sure
// the $name has the complete path and is writable.
if($overwrite) {
if(!is_writable($name)) {
return(array("error" => __("Can not over write file.")));
}
$new_file = $name;
$filename = basename($name);
}
else {
$new_file = $upload['path'] . "/$filename";
if ( ! wp_mkdir_p( dirname($new_file) ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
return array('error' => $message);
}
$new_file = $upload['path'] . "/$filename";
if ( ! wp_mkdir_p( dirname($new_file) ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
return array('error' => $message);
}
$ifp = @ fopen($new_file, 'wb');
@@ -1151,11 +1140,8 @@ function wp_upload_bits($name, $type, $bits, $overwrite = false) {
$perms = $perms & 0000666;
@ chmod($new_file, $perms);
// Compute the URL if this is a new file.
// Compute the URL
$url = $upload['url'] . "/$filename";
if($overwrite) {
$url = $name;
}
return array('file' => $new_file, 'url' => $url, 'error' => false);
}