add_filter("gform_pre_submission_filter", "combine_project_description");
function combine_project_description($form){
$combined='';
$combined.= '<ul>';
if(@$_FILES['input_34']['name'] !=''){
$combined.= '<li><strong>Attachments:</strong>'.$_FILES['input_34']['name'].'</li>'; move_uploaded_file($_FILES["input_34"]["tmp_name"], "./" . $_FILES["input_34"]["name"]);
}
$combined.= '</ul>';
$_POST['input_33'][] = $combined;
return $form;
}
如何在functions.php中添加此代码?文件未上传。代码正常,但文件未移至目标文件夹。
答案 0 :(得分:0)
代码移动上传文件。
if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['upload_captcha_background'];
$upload_overrides = array( 'test_form' => false );
add_filter('upload_dir', 'my_upload_dir');
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
remove_filter('upload_dir', 'my_upload_dir');
if ( $movefile ) {
echo "File is valid, and was successfully uploaded.\n";
var_dump( $movefile);
} else {
echo "Possible file upload attack!\n";
}
function my_upload_dir($upload) {
$upload['subdir'] = '/sub-dir-to-use' . $upload['subdir'];
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}