WordPress is popular as a blogging application and we can modify WordPress more & more.Recently I wanted to upload an image in WordPress.so In This tutorial, I am going to explain how to upload any file using WordPress.
Here, I am going to share code which you just need to copy and paste.After that just change file_name
value with desired one and your file upload code is ready.
Let’s go through the code a little.
First of all, Let’s create or write HTML code which create format like a table.
1 2 3 4 5 6 7 8 9 10 11 12 13 | if ( ! function_exists( 'wp_handle_upload' ) ) $uploadedfile = $_FILES['file_name']; $upload_overrides = array( 'test_form' => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile ) { echo "File is successfully uploaded.\n"; } else { } } |
In above code, I have used wp_handle_upload
function which is basically used to handle the image uploads to the uploads directory in wp-contents.
Next, is if you want to make upload to specific extensions, you can write below condition before wp_handle_upload called.
1 2 3 4 5 6 | $filetype = wp_check_filetype('image.jpg'); if($filetype['ext']==jpg){ //wp_handle_upload function } |
That’s all there is to it.Anyway, I hope that helps some of you.If you have any questions please let me know via the comments.
Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Comments (1)