【发布时间】:2019-01-19 16:27:37
【问题描述】:
目前我正在使用wp_upload_bits 将图像从外部上传到我的网站并且它现在可以正常工作,但是图像将我们的源 URL 作为文件名。
$post['image'] = $_POST['image'];
$upload = wp_upload_bits($_POST['image'], null, file_get_contents($_POST['image']));
$filename = $upload['file'];
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => 'cover',
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
$attach_data = wp_generate_attachment_metadata( $attach_id, $hello );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $post_id, $attach_id );
以上代码在我们的 WordPress 网站中返回的内容与此类似。
我该如何解决这个问题,以便我可以通过字符串设置我的文件名?
【问题讨论】: