0

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:
                    update_post_meta($newPost,'Uploaded_img_id',$attach_id);
                }
// END upload
4
  • 2
    you can't put slashes in a filename, it is a path separator. see this question for a potential answer.
    – Milo
    Commented Jun 14, 2013 at 16:39
  • @Milo : It's not work for me at front-end posting :( It only Work when i'm upload picture in Dashboard. Commented Jun 14, 2013 at 18:25
  • This post may help you [enter link description here][1] [1]: wordpress.stackexchange.com/q/93995/37854 Commented Oct 1, 2013 at 16:02
  • Your syntax is bad. Commented Jul 27, 2019 at 5:15

1 Answer 1

-1

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 and acknowledge you have read our privacy policy.

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