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.}
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.}
List items