I want to insert newpost on Front-end of wordpress.
And i want to rename images name during upload for my code below
Result like: "MemberUpload_dd/mm/yy_random_number_[width]x[height].jpg"
(For all size: thumbnail, medium, large, full and custom size) My code upload i'm using for my theme..
Thanks friends verymuch! ;)

// Upload 
if (!function_exists('wp_generate_attachment_metadata')){
                    require_once(ABSPATH . "wp-admin" . '/includes/image.php');
                    require_once(ABSPATH . "wp-admin" . '/includes/file.php');
                    require_once(ABSPATH . "wp-admin" . '/includes/media.php');
                 if ($_FILES) {
                    foreach ($_FILES as $file => $array) {
                        if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
                            return "Upload Err: " . $_FILES[$file]['error'];
                        $attach_id = media_handle_upload( $file, $newPost );
                if ($attach_id > 0){
                    //and if you want to set that image as Post  then use:
// END upload

I think You need to Know about using PHP to upload files as well

PHP File Upload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.