admin管理员组文章数量:1123563
Is there any permanant way to upload images via FTP to WordPress media library other than the available plugins which don't really work well most of the time? I would really appreciate if anyone could help me with this. Sorry I don't know PHP.
Thanks in advance!
Is there any permanant way to upload images via FTP to WordPress media library other than the available plugins which don't really work well most of the time? I would really appreciate if anyone could help me with this. Sorry I don't know PHP.
Thanks in advance!
Share Improve this question edited Jun 27, 2017 at 22:07 Johansson 15.4k11 gold badges43 silver badges79 bronze badges asked Jun 27, 2017 at 21:15 John DJohn D 411 bronze badge 4- Hi John, Welcome to WPSE! Can you please elaborate your question? Why can't you just use the media library to upload the images? – Johansson Commented Jun 27, 2017 at 21:26
- For photo galleries I have to upload a lot of images and uploading through media library is very slow. It would be way for faster if I could upload the images through ftp. That would help me a lot! – John D Commented Jun 27, 2017 at 21:33
- 1 It is possible to upload automatically, but not via FTP, since the images must also be stored at Database. – Johansson Commented Jun 27, 2017 at 21:37
- Benefits of using the media library: you can add alt text immediately, and you can manage those files later. If you upload in FTP your files won't be findable through the media library, and you'll have to manually include alt text as well as all of the responsive image code WP includes on its own. There are a couple of different ways to upload images in media library so I'd encourage you to explore them and find the one that saves you the most time. – WebElaine Commented Jun 27, 2017 at 21:46
1 Answer
Reset to default 0You can upload your images to your host, and then use media_sideload_image()
to upload each file. Let's assume you upload all of your images to a folder named wpse
, in the root of your WordPress installation:
// Set the directory
$dir = ABSPATH .'/wpse';
// Define the file type
$images = glob($directory . "*.jpg");
// Run a loop and upload every file to media library
foreach($images as $image) {
// Upload a single image
media_sideload_image($image,'SOME POST ID HERE');
}
Images must be attached to a post, but you can detach them afterward.
本文标签: phpImage upload via FTP to wordpress media library
版权声明:本文标题:php - Image upload via FTP to wordpress media library 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736578676a1944912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论