how to upload file in wordpress

Solutions on MaxInterview for how to upload file in wordpress by the best coders in the world

showing results for - "how to upload file in wordpress"
Martina
19 Jan 2018
1    
2    
3class WLSM_Helper {
4
5    public static function get_attachment_mime() {
6		return array('image/jpg', 'image/jpeg', 'image/png', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-rar-compressed', 'application/octet-stream', 'application/zip', 'application/octet-stream', 'application/x-zip-compressed', 'multipart/x-zip', 'video/x-flv', 'video/mp4', 'application/x-mpegURL', 'video/MP2T', 'video/3gpp', 'video/quicktime', 'video/x-msvideo', 'video/x-ms-wmv');
7	}
8
9	public static function is_valid_file( $file, $type = 'attachment' ) {
10		$get_mime = 'get_' . $type . '_mime';
11
12		if ( extension_loaded( 'fileinfo' ) ) {
13			$finfo = finfo_open( FILEINFO_MIME_TYPE );
14			$mime  = finfo_file( $finfo, $file['tmp_name'] );
15			finfo_close( $finfo );
16
17		} else {
18			$mime = $file['type'];
19		}
20
21		if ( ! in_array( $mime, self::$get_mime() ) ) {
22			return false;
23		}
24
25		return true;
26	}
27}
28
29
30# use helper class to organize your code
31
32$attachment = (isset($_FILES['attachment']) && is_array($_FILES['attachment'])) ? $_FILES['attachment'] : NULL;
33
34if (isset($attachment['tmp_name']) && !empty($attachment['tmp_name'])) {
35    if (!WLSM_Helper::is_valid_file($attachment, 'attachment')) {
36        $errors['attachment'] = esc_html__('This file type is not allowed.', 'school-management');
37    }
38}
39
40$attachment = media_handle_upload('attachment', 0);
41if (is_wp_error($attachment)) {
42    throw new Exception($attachment->get_error_message());
43}
44$data['attachment'] = $attachment;
queries leading to this page
wordpress form file uploadwordpress upload file to folderwordpress adding file upload for pluginupload data to wordpresswordpress file uploadhow to upload and access html in wordpresshow to upload wordpress projectadd upload file to form wordpress phphow to upload a word doc in wordpressupload wordpress files to new wordpress siteupload file in php wordpresshow to upload file in wordpress for freewordpress custom file uploadupload file wordpress formupload files to wordpress sitewordpress upload fileswordpress import uploadsdefine uploads wordpresswordpress save file to uploads phpupload data and files via wordpress codewordpress upload file for downloadhow to upload files to wordpressupload file php wordpressinsert the upload directory to wordpress upload filewordpress upload file in formupload image from server in wordpresscreate a image upload form in wordpressupload wordpresswordpress increse upload filehow to upload image to wordpresswordpress upload from serverwordpress upload image stepswordpress file upload phpupload to wordpress comphp upload file with wordpresshtml wordpress file upload codehow to find upload file in wordpresswordpress forms with file uploadupload file wordpressfile upload wordpresswordpress file to upload on upworkupload site to wordpressupload woff to wordpresswordpress upload files to uploads folderupload button in wordpress to save documents in wordpresswordpress file to upload how to insert files in wordpress using phphow to increase upload file in php wordpresswordpress file upload functionwordpress file upload formupload documents wordpressupload files in plugin wordpressfunction to upload file to wordpresswordpress upload documentsfile upload in wordpress custom codewordpress form with file uploadupload any file wordpresswordpress upload file form wordpress how to upload fileswordpress add files by uploadlink the upload directory to wordpress upload filehow to upload wordpress websitewordpress add uploaded file to postwhat are uploads in wordpressadd upload file to form wordpress wordpress save file to uploadswordpress plugin upload filewhen you upload files and images to a wordpress site where are they storedhow to upload a post with wordpress themeupload file to wordpressupload file programmatically wordpresswordpress upload php filehow to upload a file in wordpresshow to upload a wordpress sitefile upload in wordpress pluginwordpress file upload code exampleupload php wordpressuser upload file to wordpressupload a file to wordpress formhow to upload file in wordpress programmaticallywordpress form upload file save dbfile upload for a wordpress pagedefine upload wordpresshow to upload document on a wordpress websitephp file upload to wordpress folder programaticallyupload files to wordpresswhere store upload file from input file wordpressupload file function wordpresswordpress how to upload imagewordpress upload file functionupload file wordpress codefile upload in wordpressuploads in wordpresshow to upload files in wordpressphp wordpress require a upload filephp upload file wordpresshook to upload file to wordpressfile upload function in wordpresswordpress upload file code examplefile upload on in wordpress and get that filehow to upload documents on wordpressupload file in wordpress mediawordpress image uploadupload php file to wordpressfile upload section wordpresswordpress org uploading filesupload files wordpress optionlocal files upload wordpresswordpress form to upload fileswordpress upload ads txtform with file uploading with wordpressupload code to wordpressphp wordpress file upload codewordpress fileupload phpwordpress upload documenthow to upload a file design to wordpresshow to upload php in wordpressupload a page to wordpresshow to upload wordpress siteupload files to wordpress custom phphow to upload a wpresswordpress upload file sectionupload file in wordpress phphow to upload images to wordpressupload file input wordpresswordpress upload file with phpwordpress upload file programmaticallyhow to create file upload plugin in wordpresswordpress read files from uploadsform with file uploading wordpressupload other files wordpressupload file with wordpresshow to upload file in wordpress for freewordpress upload file form programmaticallywordpress uploadupload file with wordpress formfile upload in wordpress phpwordpress upload fileupload custom file in wordpress upload codeupload file to wordpress phphow to upload the website files to wordpressuploads wordpresshow to upload website files to wordpresswordpress file upload code how to upload file in wordpresscan i upload my files on site created using wordpresshow to upload image in wordpresswordpress form add file uploadexport uploads wordpressupload file in wordpress php codeupload files in wordpresshow to get to wordpress uploads from upload files to wordpress for downloadimage upload for a wordpress pagewordpress upload file plugincreate a upload page wordpresswhere shoul i upload files wordpresswordpress plugin file upload and email attachment formhow to upload my wordpress sitewordpress upload file phpwordpress file uploader function examplewordpress file upload plugin 24upload wordpress custom fileswordpress file upload into uploadshow to upload code files on wordpresswordpress uploaderupload file in wordpress pluginwordpress how to handle file uploadmanually upload and setup wordpresswordpress file uploadimport upload to wordpresshow to use wordpress image uploaddownload from uploads wordpresswordpress upload file customwordpress plugin file upload and email formwordpress upload file for linkhow to upload file in wordpress