Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if( isset($this->data['file']) ) {
- $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' );
- if ( in_array($this->data['file']['type'], $allowed_types) ) {
- //move temp file
- $upload_dir = wp_upload_dir();
- $upload_dir = $upload_dir['path'];
- $tmp_name = $this->data['file']['tmp_name'];
- $name = $this->data['file']['name'];
- move_uploaded_file( $tmp_name, "$upload_dir/$name" );
- $file = "$upload_dir/$name";
- //get file url
- $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
- $content_dir = untrailingslashit( WP_CONTENT_DIR );
- $file = wp_normalize_path( $file );
- $content_dir = wp_normalize_path( $content_dir );
- $url = str_replace( $content_dir, $content_url, $file );
- $attachments = array( 'file' => $file, 'url' => $url, 'name' => $name );
- $this->data['attachments'] = $attachments;
- }
- unset($this->data['file']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement