You appear to be a bot. Output may be restricted
Description
Return a JSON encoded array for attached media fileThe media array is expected to consist of:
- url – the attachment URL e.g. http://qw/oikcom/wp-content/uploads/2015/03/oik-clone-v0.6.zip
- file – the file name e.g. oik-clone-v0.6.zip
- md5 – the MD5 calculated hash of the base64 encoded contents e.g. 5b3f0cf1c13169de99ad3e94d201d7cd
- data – the base64 encoded file contents.
- name – the file name
- type – the file type e.g. text/plain
- tmp_name – the filename where it's been stored temporarily
- error
- size
Usage
$string = oik_clone_load_media_file( $id, $payload );
Parameters
- $id
- ( ID ) required – the post ID of the attachment
- $payload
- ( mixed ) required –
Returns
string the JSON encoded media fileSource
File name: oik-clone/admin/oik-clone-media.phpLines:
1 to 27 of 27
function oik_clone_load_media_file( $id, $payload ) { //static $jmedia; //if ( empty( $jmedia ) ) { $media_file = array(); if ( $payload->post_type == "attachment" ) { $media_file['url'] = bw_array_get( $_REQUEST, "attachment_url", null ); $media_file['type'] = $payload->post_mime_type; $file = get_post_meta( $id, "_wp_attached_file", true ); $media_file['name'] = basename( $file ); $full_file = oik_clone_determine_full_file( $file ); $media_file['file'] = $full_file; $media_file = oik_clone_filter_media_file( $media_file, $payload ); $contents = file_get_contents( $media_file['file'] ); $media_file['md5'] = md5( $contents ); $base64 = oik_clone_load_media_file_base64( $contents ); // $media_file['md5'] = md5( $base64 ); $media_file['size'] = filesize( $media_file['file'] ); $media_file['data'] = $base64; $media_file['file'] = $full_file; bw_trace2( $media_file, "media_file" ); } $jmedia = json_encode( $media_file ); //} return( $jmedia ); }View on GitHub