Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




wp_upload_bits [ WordPress Function ]

wp_upload_bits ( $name, $deprecated, $bits, $time = null )
Parameters:
  • (string) $name
  • (null) $deprecated Never used. Set to null.
  • (mixed) $bits File content
  • (string) $time Optional. Time formatted in 'yyyy/mm'.
Returns:
  • (array)
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_pdirname$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 = @ statdirname$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ý

Dahasý ...

Kullanýcý Tartýþmalarý [ wordpress.org ]

- Bulunamadý -

Yeni bir konu yaz ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics