How does wordPress save the uploaded images in the plugin under the corresponding plugin directory?

Source: Internet
Author: User
Developed a plugin has an upload image function, the plugin below a directory is IMG Save the picture, want to ask how to save the uploaded ah pictures to this directory?

Check The nonce is valid, and the user can edit this post.if (isset ($_post[' my_image_upload_nonce '), $_post[' P ost_id ']) && wp_verify_nonce ($_post[' my_image_upload_nonce '), ' my_image_upload ') && Current_user_ca    N (' edit_post ', $_post[' post_id ')) {//the nonce was valid and the user have the capabilities, it's safe to continue.    These files need to being included as dependencies when on the front end. Require_once (Abspath.    ' wp-admin/includes/image.php '); Require_once (Abspath.    ' wp-admin/includes/file.php '); Require_once (Abspath.    ' wp-admin/includes/media.php ');    Let WordPress handle the upload.    Remember, ' My_image_upload ' is the name of our file, and our form above. $url =wpwsl_plugin_url. '/img/'. $imageSize.    '. png ';//Update_option (' Upload_path ', Wp_content_dir. '/uploads '); Update_option (' Upload_path ', Wpwsl_plugin_url.    /img/');    $attachment _id = media_handle_upload (' my_image_upload ', $_post[' post_id ']); if (Is_wp_error ($attachment _id)) {//There is an error uploading the image. echo "

There is an error uploading your file.

"; } else {//the image was uploaded successfully! echo "

The image was uploaded successfully!

"; Add_filter (' img ', $attachment _id);//Add_filter (' img ', ' custom_upload_directory '); }} else {echo "

The security check failed, maybe show the user an error

"; The security check failed, maybe show the user an error.}
    1. List items

                                                             
  
                       

Reply content:

Developed a plugin has an upload image function, the plugin below a directory is IMG Save the picture, want to ask how to save the uploaded ah pictures to this directory?

Check The nonce is valid, and the user can edit this post.if (isset ($_post[' my_image_upload_nonce '), $_post[' P ost_id ']) && wp_verify_nonce ($_post[' my_image_upload_nonce '), ' my_image_upload ') && Current_user_ca    N (' edit_post ', $_post[' post_id ')) {//the nonce was valid and the user have the capabilities, it's safe to continue.    These files need to being included as dependencies when on the front end. Require_once (Abspath.    ' wp-admin/includes/image.php '); Require_once (Abspath.    ' wp-admin/includes/file.php '); Require_once (Abspath.    ' wp-admin/includes/media.php ');    Let WordPress handle the upload.    Remember, ' My_image_upload ' is the name of our file, and our form above. $url =wpwsl_plugin_url. '/img/'. $imageSize.    '. png ';//Update_option (' Upload_path ', Wp_content_dir. '/uploads '); Update_option (' Upload_path ', Wpwsl_plugin_url.    /img/');    $attachment _id = media_handle_upload (' my_image_upload ', $_post[' post_id ']); if (Is_wp_error ($attachment _id)) {//There is an error uploading the image. echo "

There is an error uploading your file.

"; } else {//the image was uploaded successfully! echo "

The image was uploaded successfully!

"; Add_filter (' img ', $attachment _id);//Add_filter (' img ', ' custom_upload_directory '); }} else {echo "

The security check failed, maybe show the user an error

"; The security check failed, maybe show the user an error.}
    1. List items

                                                             
  
                       
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.