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