Last active
April 3, 2018 06:17
-
-
Save dcangulo/40d2f4a382bb5b78b97b55592b535a1e to your computer and use it in GitHub Desktop.
A simple WordPress plugin that allows you to upload files programatically. Visit https://www.davidangulo.xyz/ for more information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Upload Files Programatically | |
Plugin URI: https://wordpress.org/plugins/ | |
Description: Just another file uploader plugin. | |
Version: 1.0.0 | |
Author: David Angulo | |
Author URI: https://www.davidangulo.xyz/ | |
*/ | |
function myFileUploader() { | |
if(isset($_POST["submit"])) { | |
wp_upload_bits($_FILES['fileToUpload']['name'], null, file_get_contents($_FILES['fileToUpload']['tmp_name'])); | |
} | |
echo '<form action="" method="post" enctype="multipart/form-data"> | |
<input type="file" name="fileToUpload" id="fileToUpload"> | |
<input type="submit" value="Upload Image" name="submit"> | |
</form>'; | |
} | |
function myFileUploaderRenderer() { | |
ob_start(); | |
myFileUploader(); | |
return ob_get_clean(); | |
} | |
add_shortcode("custom_file_uploader","myFileUploaderRenderer"); | |
//Visit the tutorial for more information | |
//https://www.davidangulo.xyz/website-development/how-to-upload-files-in-wordpress-programmatically/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment