Remote Attachment for Custom post Type

I have a plugin that operates with another system I’ve written – the other system has a store of over 100,000 images, and each website picks from the library and displays the images on the appropriate post as per usual.

The problem is – I am copying each file to each website as an attachment to the post, making each website over 10GB in size and almost unmanageable.

How can I, through PHP, remote link to a file and have wordpress still view it as an attachment for use in a gallery? It seems trivial to just use the URL instead of having it pull from the uploads directory when adding attachments during my import routines but I can’t figure it out.

So – have a remote file treated as a local file from the uploads directory in wordpress?

  • Michelle Shull
    • DEV MAN’s Apprentice

    Hey there, Dan!

    This is a bit above my skill level, but I have some ideas.

    1. I think we’ll need to take advantage of oEmbed here. There’s a plugin that lets users connect remote libraries – it’s built specifically to support YouTube, Vimeo, and Flickr, but I suspect you could find some useful direction in their plugin code: http://tidyrepo.com/remote-media-libraries/

    2. I think there might also be a way to tie this into a custom field, as well, but it would take some code sorcery to only import media files as your sites needed them.

    Let’s ask our Second Level Code gurus to take a look here and see if there’s a more elegant way to approach this. This may actually be a job for a dev you hire independently, if our SLS team is unable to find a quick solution, and it can take a little more time to get a response from them since they’re working on the more complex member issues. If it’s critical, you may want to speak to a dev sooner.

    Thanks for your question!

  • Hoang Ngo
    • The Green Incsub

    Hi @Dan,

    I hope you are well today.

    I see your issue, but with WordPress, only update URL is not enough, fortunately, I found this plugin which I think can help https://wordpress.org/plugins/media-from-ftp/

    The idea is you will have a server using for storage, and when you upload/modify media from your WordPress site, it’s transfer to your storage server (via FTP), and link back to your WordPress site. This way, you can easier for management :slight_smile:

    Please let me know if it help for you :slight_smile:

    Best regards,

    Hoang