简体   繁体   English

将照片上传到另一个域

[英]Upload a photo to another domain

I have a number of different domains where I would like users to be able to select a photo, however I want to photos uploaded/stored on one central separated domain. 我有多个不同的域,希望用户可以选择照片,但是我想将照片上传/存储在一个中央分隔的域中。

Is there a more advisable way to do this? 有更明智的方法吗?

I've considered using an iframe from the other domain (so they are interacting with the required domain) but haven't tried it yet. 我曾考虑过使用其他域中的iframe(因此它们正在与所需域进行交互),但尚未尝试过。

I have also read that curl can potentially do this. 我也读过curl可以做到这一点。

Any other ideas/problems/concerns... 其他任何想法/问题/疑虑...

All advise appreciated. 所有建议表示赞赏。

thx 谢谢

There are a couple ways you can handle this. 有几种方法可以解决此问题。 Here are the scenarios I see. 这是我看到的情况。

Scenario A: All domains are on the same server. 方案A:所有域都在同一服务器上。 With this setup you can actually help your server security by storing the images and other files in a directory that is not accessible by Apache. 通过此设置,您实际上可以通过将图像和其他文件存储在Apache不能访问的目录中来帮助提高服务器的安全性。 Then you use PHP to serve the file to the end user through virtual links. 然后,您使用PHP通过虚拟链接将文件提供给最终用户。 Drupal does this with its private file system. Drupal通过其专用文件系统来做到这一点。

If the users are able to upload images from the other domains then just have all of the domains write the images to the same directory, but then always return the "central" domain's URL for retrieving them. 如果用户能够从其他域上载图像,则只需让所有域将图像写入同一目录即可,但是始终返回“中央”域的URL来检索它们。

Scenario B: The domains exist across two or more servers. 方案B:域存在于两个或多个服务器之间。 With this setup what you really need to do is setup an API where the other domains communicate behind the scenes to send the photo to the core repository domain. 通过此设置,您真正需要做的是设置一个API,其他域在后台进行通信,以将照片发送到核心存储库域。 This domain saves it and returns a URL for accessing it. 此域将其保存并返回用于访问它的URL。

In either case you should really look up CDN technology. 无论哪种情况,您都应该真正使用CDN技术。 Its basically what your trying to accomplish plus a lot more. 基本上,这是您要完成的工作以及更多的事情。 I would also recommend that in either scenario that you always use the path on the central domain for all the images instead of returning them back through the current domain. 我还建议在这两种情况下,始终对所有图像使用中央域上的路径,而不是通过当前域将它们返回。

No reason to get iframes or curl involved. 没有理由让iframe或curl参与其中。 Assuming that all these domains are on the same server (or same cluster of servers), there is nothing which requires that a file uploaded using a file on one domain must only be served from that domain. 假设所有这些域都在同一台服务器(或同一服务器集群)上,则没有什么要求使用一个域上的文件上传的文件只能从该域提供。 An upload form can do whatever it wants with the uploaded file, including storing it in a location where it'll be available from your central domain. 上传表单可以对上传的文件进行任何处理,包括将其存储在可从您的中央域访问的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM