我正在制作一个插件,它将在WordPress的“ UPLOADS”文件夹中的自定义文件夹中上传pdf文件,并将路径插入MySQL数据库中。我检查了Stack Overflow中的各种答复,但似乎对我没有用。插件将不会上传文件,也不会将其插入数据库中
/********* START OF ************
********** INSERTION OF DATA AND UPLOADING FILE IN CUSTOM DIRECTORY ***********/
if($_POST['upload_pdf']) {
global $wpdb;
$table_name =$wpdb->prefix . 'pdf_file_registry';
$tmpp_name = $_FILE['pdf_select']['tmp_name'];
if($_FILES['pdf_select']['type'] == "application/pdf") {
$uploadedfile = $_FILES['pdf_select'];
add_filter( 'upload_dir', 'wpse_183245_upload_dir' );
function wpse_183245_upload_dir( $dirs ) {
$dirs['subdir'] = '/pdf_upload_directory';
$dirs['path'] = $dirs['basedir'] . '/pdf_upload_directory';
$dirs['url'] = $dirs['baseurl'] . '/pdf_upload_directory';
return $dirs;
}
$movefile = wp_handle_upload($uploadedfile);
remove_filter( 'upload_dir', 'wpse_183245_upload_dir' );
$pdf_file_name = $_FILE['pdf_select']['name'];
$category_name = $_POST['category_name'];
$pdf_title = $_POST['pdf_title'];
$pdf_path = "test";
$success = $wpdb->insert("wp_pdf_file_registry", array(
"pdf_file_name" => $pdf_file_name,
"pdf_title" => $pdf_title,
"pdf_category" => $category_name,
"pdf_path" => $pdf_path,
));
if($success) {
echo ' Inserted successfully';
} else {
echo 'not';
}
}
}
/********* END OF ************
********** INSERTION OF DATA AND UPLOADING FILE IN CUSTOM DIRECTORY ***********/
我在哪里弄错了?