how to change file upload default directory to custom directory


I have created a custom file upload method on wordpress but it only uploads only uploads folder.

I want to move it to custom directory on upload directory :
like this uploads/my_folder i want to upload on my_folder directory.

Here is my code:

add_action( 'wp_ajax_file_upload', 'file_upload_callbacks' );
add_action( 'wp_ajax_nopriv_file_upload', 'file_upload_callbacks' );

function file_upload_callbacks() {
    $arr_img_ext = array('application/pdf');
 if (in_array($_FILES['file']['type'], $arr_img_ext)) {
     $upload = wp_upload_bits($_FILES["file"]["name"], null, file_get_contents($_FILES["file"]["tmp_name"]));
     //$upload['url'] will gives you uploaded file path


     wp_send_json( $upload['url'] );
Sabbir 2 months 0 Answers 7 views 0

Leave an answer