php - Wordpress Custom Plugin Upload Image -
I am writing a custom wordpress plugin which lets the user upload images in a folder. And I'm having trouble saving the original image to the folder
This is my myplugin.php
add_action ('admin_menu', 'register_my_custom_menu_page'); Function register_my_custom_menu_page () {add_menu_page ('home page', 'home page', 'management_option', 'homepage', 'my_custom_menu_page', plugins_url ('myplugin / images / icon.png'), 6); } Function my_custom_menu_page () {echo '& lt; H1 & gt; Settings & lt; / H1> '; Echo '& lt; Form method = "post" action = "process.php" enctype = "multipart / form-data" & gt; '; Echo & lt; Table & gt; '; Echo '& lt; Tr & gt; & Lt; Td> Image 1 & lt; / Td> & Lt; Td> & Lt; Input type = "file" name = "file1" size = "40" & gt; & Lt; / Td> & Lt; / Tr & gt; '; Echo '& lt; Tr & gt; & Lt; Td> & Lt; / Td> & Lt; Td> & Lt; Input type = "submit" name = "submit" value = "update" /> gt; & Lt; / Td> & Lt; / Tr & gt; '; Echo '& lt; / Table & gt; '; Echo '& lt; / Form & gt; '; }
This is my process.php, and I do not see the image inside my wp upload folder. help please!
move_uploaded_file ($ _ FILES ["cul_center"] ["tmp_name"], wp_upload_dir (). $ _ Files ["file1"] ["name"]);
You do not need to use PHP native functions for this.
Provides a function to handle WordPress uploads and to explicitly transfer them to / upload / year / month /
.
Usage (in your case):
requirement_ense (abpsp. 'Wp-admin / include / file.php'); // file is required file.php uploaded file = $ _FILES ['file1']; // your file input $ upload_overrides = array ('test_form' = & gt; wrong); // You have to do this according to the docs $ movefile = wp_handle_upload ($ uploaded file, $ upload_overrides); // Allow it to handle uploads ($ movefile) {echo "file is valid, and was uploaded successfully. \ N"; Var_dump ($ transfer file); // prints the associative array of file attributes }
Comments
Post a Comment