Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. if( isset($this->data['file']) ) {
  2.  
  3. $allowed_types = array('image/png', 'image/jpg', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xls', 'application/msword', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
  4.  
  5. if ( in_array($this->data['file']['type'], $allowed_types) ) {
  6.  
  7. //move temp file
  8. $upload_dir = wp_upload_dir();
  9. $upload_dir = $upload_dir['path'];
  10.  
  11. $tmp_name = $this->data['file']['tmp_name'];
  12. $name = $this->data['file']['name'];
  13. move_uploaded_file( $tmp_name, "$upload_dir/$name" );
  14. $file = "$upload_dir/$name";
  15.  
  16. //get file url
  17. $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
  18. $content_dir = untrailingslashit( WP_CONTENT_DIR );
  19. $file = wp_normalize_path( $file );
  20. $content_dir = wp_normalize_path( $content_dir );
  21. $url = str_replace( $content_dir, $content_url, $file );
  22.  
  23. $attachments = array( 'file' => $file, 'url' => $url, 'name' => $name );
  24.  
  25. $this->data['attachments'] = $attachments;
  26. }
  27. unset($this->data['file']);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement