Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question
1  
you can't put slashes in a filename, it is a path separator. see this question for a potential answer. –  Milo Jun 14 '13 at 16:39
    
@Milo : It's not work for me at front-end posting :( It only Work when i'm upload picture in Dashboard. –  Zen Nguyễn Jun 14 '13 at 18:25
    
This post may help you [enter link description here][1] [1]: wordpress.stackexchange.com/q/93995/37854 –  usama sulaiman Oct 1 '13 at 16:02

1 Answer 1

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

PHP File Upload

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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