Before you go over the snippets I will summarize which functions are being used.
That's it! one function that would insert the image into the DB, create four copies with different sizes, and upload to the uploads directory. Regarding the arguments:
'image' is what holds all the data about the image. It comes from the POST request. In the JS file you will see what I mean.
'0' This is the $post_id. I set it to zero, because i'm not asigning this image to any post at the moment. In order for this function to work we need to add above it:
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
You will probably want to create your own validation rules. Even before you send the AJAX call. I'm only showing you how to upload the image, but not to secure it. Maybe I will add it later.
Hi, thanks for the script, but what about, if I want to attach the image to the specific category, how can I do that ?