Last active
June 13, 2019 12:16
-
-
Save mhasan3/1f6688a140bccbe36e160426cc778a3e to your computer and use it in GitHub Desktop.
Revisions
-
mhasan3 revised this gist
Jun 13, 2019 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <form name="artist_basic_profile" id="artist_basic_profile" action="" method="post" enctype="multipart/form-data"> <?php if($user->ID){ ?> <input type="file" id="userProfileImage" name="userProfileImage" > <input id="submit" type="submit" name="submit" value="Save" > <?php } ?> </form> -
mhasan3 revised this gist
Jun 13, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ <form name="artist_basic_profile" id="artist_basic_profile" action="" method="post" enctype="multipart/form-data"> <?php if($user->ID){ ?> <input type="file" id="userProfileImage" name="userProfileImage" > <input id="submit" type="submit" name="submit" value="Save" > <?php } ?> </form> -
mhasan3 created this gist
Jun 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ require_once(ABSPATH . '/wp-load.php'); require_once(ABSPATH . "wp-admin" . '/includes/file.php'); require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $filename = $_FILES['userProfileImage']['name']; if($filename){ $uploaddir = wp_upload_dir(); // get wordpress upload directory $myDirPath = $uploaddir['path']; $myDirUrl = $uploaddir['url']; $MyImage = rand(0, 5000) . $_FILES['userProfileImage']['name']; $image_path = $myDirPath . '/' . $MyImage; move_uploaded_file($_FILES['userProfileImage']['tmp_name'], $image_path); $file_array = array( 'name' => $_FILES['userProfileImage']['name'], 'type' => $_FILES['userProfileImage']['type'], 'tmp_name' => $_FILES['userProfileImage']['tmp_name'], 'error' => $_FILES['userProfileImage']['error'], 'size' => $_FILES['userProfileImage']['size'], ); $file = $MyImage; $uploadfile = $myDirPath . '/' . basename($file); $filename = basename($uploadfile); $wp_filetype = wp_check_filetype(basename($filename), null); $attachment = array( 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $_FILES['userProfileImage']['name']), 'post_content' => '', 'post_status' => 'inherit' ); $attachment_id = wp_insert_attachment($attachment, $uploadfile); $attach_data = wp_generate_attachment_metadata($attachment_id, $uploadfile); $attachimage_url = $uploaddir['url'] . '/' . basename($filename); wp_update_attachment_metadata($attachment_id, $attach_data); update_field('profile_image', $attachment_id, "user_" . $current_user_id); }