admin管理员组文章数量:1302418
I would like to be able to get the URL of a html file that has been uploaded to a folder via FTP.
So if I go into a post in the admin back end of WordPress, I would like there to be a custom field with a file browser that would list the html files and subdirectories in: wp-content/uploads/articles/
Then when a file has been selected it will log the url of that file so it can be retrieved on the front end.
I've done countless searches on Google and here and can't seem to find the answer I'm looking for. Would just like to know if it can or cant't be done so I can plan accordingly.
Any insight would be greatly appreciated!
I would like to be able to get the URL of a html file that has been uploaded to a folder via FTP.
So if I go into a post in the admin back end of WordPress, I would like there to be a custom field with a file browser that would list the html files and subdirectories in: wp-content/uploads/articles/
Then when a file has been selected it will log the url of that file so it can be retrieved on the front end.
I've done countless searches on Google and here and can't seem to find the answer I'm looking for. Would just like to know if it can or cant't be done so I can plan accordingly.
Any insight would be greatly appreciated!
Share Improve this question asked Mar 7, 2021 at 0:48 Adam GilliesAdam Gillies 231 silver badge5 bronze badges1 Answer
Reset to default 0You can scan the directory for files with glob()
then loop throw the results and list them in a admin modal (thickbox) or just show the list within a admin metabox in the post editor.
Here's a little snippet that i was playing with.
/**
* Get HTML Article Files from uploads/articles
* Support both .htm & .html ext.
*
* @return array List of html article files with path & url.
*/
function wpse_384622_get_articles() {
$uploads = wp_upload_dir();
$file_path = $uploads['basedir'] . '/articles/';
$file_url = $uploads['baseurl'] . '/articles/';
$articles = [];
foreach ( glob( $file_path . '*.htm*' ) as $path ) {
if ( is_readable( $path ) ) {
$file_type = wp_check_filetype( $path );
if ( 'text/html' === $file_type['type'] ) {
$file_list[] = [
'path' => $path,
'url' => str_replace( $file_path, $file_url, $path ),
];
}
}
}
return $articles;
}
本文标签: htmlAdmin back endget URL of file using file browser
版权声明:本文标题:html - Admin back end - get URL of file using file browser 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741698848a2393170.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论