Add wp_upload_bits(). Attempt to fix mw_newMediaObject().

git-svn-id: https://develop.svn.wordpress.org/trunk@3255 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2005-12-01 22:51:40 +00:00
parent b6a751dc30
commit 96a472460d
2 changed files with 57 additions and 64 deletions

View File

@@ -778,4 +778,37 @@ function get_post_mime_type($ID = '') {
function get_attached_file($attachment_id) {
return get_post_meta($attachment_id, '_wp_attached_file', true);
}
function wp_upload_bits($name, $type, $bits) {
if ( empty($name) )
return array('error' => "Empty filename");
$upload = wp_upload_dir();
if ( $upload['error'] !== false )
return $upload;
$number = '';
$filename = $name;
while ( file_exists($upload['path'] . "/$filename") )
$filename = str_replace("$number.$ext", ++$number . ".$ext", $filename);
$new_file = $uploads['path'] . "/$filename";
$ifp = @ fopen($new_file, 'wb');
if ( ! $ifp )
return array('error' => "Could not write file $new_file.");
$success = @ fwrite($ifp, $bits);
fclose($ifp);
// Set correct file permissions
$stat = @ stat(dirname($new_file));
$perms = $stat['mode'] & 0000777;
@ chmod($new_file, $perms);
// Compute the URL
$url = $upload['url'] . "/$filename";
return array('file' => $new_file, 'url' => $url);
}
?>