summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-includes/functions-post.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-inst/wp-includes/functions-post.php')
-rw-r--r--wp-inst/wp-includes/functions-post.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/wp-inst/wp-includes/functions-post.php b/wp-inst/wp-includes/functions-post.php
index c4205cb..38c1cfe 100644
--- a/wp-inst/wp-includes/functions-post.php
+++ b/wp-inst/wp-includes/functions-post.php
@@ -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);
+}
+
?>