May 11th, 2020

Part 2: WordPress Plugin Uploading Media and using Web Services

Uploading Files

The goal of the plugin is to convert a PDF in WordPress’ media directory into HTML using the web service. So first of all we need to extend the plugin we created last time to have a form which handles the uploads. We also need to handle the incoming file, which we do in test_handle_post(), where we use the media_handle_upload() function to upload the file to the media folder. Below is the commented code of how to do so:

The admin page should now look like this when a file has been uploaded:

upload

And to verify it went into the media folder:pdf

Now we want to actually convert the file to html using the web service (Note: We no longer provide a SOAP service, so the below code is out of date, but you can learn more about how to convert PDFs to HTML5/SVG in PHP here). Below I have amended the conversion method onto the plugin:

And if we look in the output directory of the plugin folder, we should see our converted document:

output

Now that we know how to upload a PDF file to the media directory, it is also possible to create list of the files to display and then select which one to use. I won’t mention how to do it here for the sake of brevity but if you’re interested in trying this, have a look at get_posts() method on the WordPress Codex.

Collected

Leave a Reply

Your email address will not be published. Required fields are marked *

recent post

Part 3: WordPress…

Recently, I’ve been working on a proof of concept project which int...

 691 Views
Part 2: WordPress…

Uploading Files The goal of the plugin is to convert a PDF in WordPre...

 761 Views
Part 1: WordPress…

WordPress is one of the most popular content management systems on the...

 713 Views
CSS Hacks For Every Web Developer
CSS Browser-Specific Hacks

What is this? Browser hacks is an extensive list of brow...

 1060 Views
What are Operators…

Operators are symbols or keywords that tell the JavaScript engine to...

 409 Views
CSS3 Visual Formatting…

The CSS3 visual formatting model is the algorithm that is used to pro...

 404 Views
Animatable Properties in CSS3
Animatable Properties in…

The following section contains a complete list of animatable propert...

 422 Views
Custom Permalinks in…

Do you want to create custom permalinks in WordPress for posts, page...

 381 Views
HTML5 Tag Reference

HTML5 has many new tags included and many others deprecated from the...

 394 Views
Resize and Make…

Have you ever tried resizing a image to make it larger? This usually...

 409 Views