上载过程中重命名上载图像

时间:2013-06-14 作者:Zen Nguyễn

我想在wordpress的前端插入newpost
我想在上载过程中重命名图像名称for my code below
结果如下:“MemberUpload\\uem>日/月/年\\u random\\u number\\u[宽度]x[高度]。jpg”
(适用于所有大小:缩略图、中、大、全尺寸和自定义大小)我的代码上载我用于我的主题<(非常感谢朋友们!)

// 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

1 个回复
SO网友:usama sulaiman

我认为您还需要了解如何使用PHP上传文件

PHP File Upload

结束