upload excel file to wordpress media from simple php file script -


i want upload excel file wordpress outside php file script .i tried search not got.

can 1 me in this?

if ( !function_exists('media_handle_upload') ) {         require_once(abspath . "wp-admin" . '/includes/image.php');         require_once(abspath . "wp-admin" . '/includes/file.php');         require_once(abspath . "wp-admin" . '/includes/media.php');     }     $url = "http://example.com/demo.xls";     $tmp = download_url( $url );     if( is_wp_error( $tmp ) ){         // download failed, handle error     }     $post_id = 1;     $desc = "description";     $file_array = array();      // set variables storage     // fix file filename query strings     preg_match('/[^\?]+\.(jpg|jpe|jpeg|xls|png)/i', $url, $matches);     $file_array['name'] = basename($matches[0]);     $file_array['tmp_name'] = $tmp;      // if error storing temporarily, unlink     if ( is_wp_error( $tmp ) ) {         @unlink($file_array['tmp_name']);         $file_array['tmp_name'] = '';     }      // validation , storage stuff      $id = media_handle_sideload( $file_array, $post_id, $desc );      // if error storing permanently, unlink     if ( is_wp_error($id) ) {         @unlink($file_array['tmp_name']);         return $id;     }      $src = wp_get_attachment_url( $id ); 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -