wp_upload_bits [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Create a file in the upload folder with given content.
If there is an error, then the key 'error' will exist with the error message. If success, then the key 'file' will have the unique file path, the 'url' key will have the link to the new file. and the 'error' key will be set to false.
This function will not move an uploaded file to the upload folder. It will create a new file with the content in $bits parameter. If you move the upload file, read the content of the uploaded file, and then you can give the filename and content to this function, which will add it to the upload folder.
The permissions will be set on the new file automatically by this function.
Source
<?php
function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, '2.0' );
if ( empty( $name ) )
return array( 'error' => __( 'Empty filename' ) );
$wp_filetype = wp_check_filetype( $name );
if ( !$wp_filetype['ext'] )
return array( 'error' => __( 'Invalid file type' ) );
$upload = wp_upload_dir( $time );
if ( $upload['error'] !== false )
return $upload;
$upload_bits_error = apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, 'time' => $time ) );
if ( !is_array( $upload_bits_error ) ) {
$upload[ 'error' ] = $upload_bits_error;
return $upload;
}
$filename = wp_unique_filename( $upload['path'], $name );
$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' );
if ( ! $ifp )
return array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
@fwrite( $ifp, $bits );
fclose( $ifp );
clearstatcache();
// Set correct file permissions
$stat = @ stat( dirname( $new_file ) );
$perms = $stat['mode'] & 0007777;
$perms = $perms & 0000666;
@ chmod( $new_file, $perms );
clearstatcache();
// Compute the URL
$url = $upload['url'] . "/$filename";
return array( 'file' => $new_file, 'url' => $url, 'error' => false );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp upload bits « WordPress Codex
Description. Create a file in the upload folder with given content. If there is an error, then the key 'error' will exist with the error message. If success, then the key ...
codex.wordpress.org - #12493 (Filter $bits in wp_upload_bits()) – WordPress Trac
It'd be nice if there was a filter on $bits in wp_upload_bits() to allow plugins to modify uploads coming in from XML-RPC. Resizing, watermarking, etc. are all ...
core.trac.wordpress.org - wp_upload_bits - PHP Cross Reference of WordPress Source - Yoast
Jun 1, 2011 ... Function and Method Cross Reference. wp_upload_bits(). Defined at: /wp- includes/functions.php -> line 2351. Referenced 2 times: ...
xref.yoast.com - wp_upload_bits | A HitchHackers guide through WordPress
Feb 12, 2011 ... function wp_upload_bits( $name, $deprecated, $bits, $time = null ) {} ... apply_filters( 'wp_upload_bits', array( 'name' => $name, 'bits' => $bits, ...
hitchhackerguide.com