admin管理员组

文章数量:1312996

I'm using the latest WordPress (5.6) and from what I've found out there's no visible setting for uploading media directly to a DB. Is there such an option somewhere hidden or does WordPress not support DB as a media storage instead of wp-content/uploads?

I'd like to utilize DB as prioritized (or the only, if possible) storage instead of filesystem and then load the media (such as post images) directly from the DB.

I'm using the latest WordPress (5.6) and from what I've found out there's no visible setting for uploading media directly to a DB. Is there such an option somewhere hidden or does WordPress not support DB as a media storage instead of wp-content/uploads?

I'd like to utilize DB as prioritized (or the only, if possible) storage instead of filesystem and then load the media (such as post images) directly from the DB.

Share Improve this question edited Dec 30, 2020 at 21:09 Peter Badida asked Dec 30, 2020 at 20:52 Peter BadidaPeter Badida 1074 bronze badges 1
  • This is not supported by wordpress. – Picard102 Commented Dec 31, 2020 at 17:47
Add a comment  | 

1 Answer 1

Reset to default 2

Yes, out of the box WordPress stores images and other uploads only as files.

Although it could be, theoretically, possible to change this behavior by tapping inton wp_handle_upload() or _wp_handle_upload() and related functions, I think it would be too complex and unreliable. Besides,I think it wouldn't be a good idea for performance reasons in case with too many images (then again, I am not a DB specialist)

And just for good measure, if you want to change uploads folder location, you can do it by defining the UPLOADS constant in wp-config.php file:

define( 'UPLOADS', 'new-folder-for-uploads' );

Edit 1

Adding my response to the Peter Badida comment about :

I can't tell for sure, but I think you could experiment with the filesystem_method_file filter on the WP_Filesystem function, located at line 1867 of /wp-admin/includes/file.php and add your own abstractions.

Bear in mind that plugins and themes will probably use functions, actions and filters that rely on a disk based filesystem. So you will need to keep a lot of the current filesystem for compatibility and make things more complex than needed. Great intelectual and WP developing challenge, but from a pragmatic perspective, I would stick to the default filesystems.

Edit 2 (from comment)

WordPress is built in a way that you can override or extend a lot of its functionality mostly by using filters and actions hooks. Stick to them and you will have far fewer headaches and imcompatibility issues.

Here you can find all or most of the hooks. Also, you might want to search for apply_filter and do_actionstrings on WordPress Core codebase.

本文标签: imagesUpload media only to DB