如何用php上传到静态内容服务器?
我很快就会启动一个 Web 应用程序,该应用程序将提供相当数量的图像,因此我希望有一个主 Web 服务器和一个静态内容服务器,稍后可能还有一个单独的数据库服务器。
我希望用户:
- 登录并能够上传照片
- 照片被重命名为随机字符串
- 照片被处理成缩略图
- 照片和缩略图存储到静态服务器上的文件系统中。
- 照片和缩略图的目录和文件名存储在 mysql 数据库中
问题是我不知道如何让用户立即将图像上传到单独的服务器。
我考虑过使用 amazon s3,但在发布文件名之前无法编辑文件名。 (通过POST,我宁愿不使用REST api)
我也可以使用php的ftp功能上传到单独的服务器,但我想根据图像的属性动态创建文件夹(所以我不显然,所有图像都在一个大文件夹中),但我不知道如果我使用 ftp 这会如何工作...
或者我可以将它们保存在本地并使用 CDN,我对 CDN 不太熟悉,所以我不不知道以这种方式使用它们是否合适或具有成本效益。
我在这里有什么选择?我希望图像能够立即可用(没有 cron 作业/队列)
谢谢。
I am launching a web application soon that will be serving a fair amount of images so I'd like to have a main web server and a static content server and possibly a separate database server later on.
I'd like the user to:
- login and be able to upload a photo
- the photo is renamed a randrom string
- the photo is processed into a thumbnail
- the photo and thumbnail are stored into a filesystem on the static server.
- the photo and thumbnail's directory and filename are stored in a mysql database
The problem is I don't know how to have the user instantly upload an image to a separate server.
I thought about using amazon s3, but you can't edit filenames before posting them. (through POST, I'd rather not use the REST api)
I could also use php's ftp function to upload to a separate server, but I'd like to dynamically create folders based on the properties of the image (so I don't have all the images in one big folder obviously), but I don't know how this would work if I used ftp...
Or I could save them locally and use a CDN, I'm not too familiar with CDN's so I don't know if using them this way would be appropriate or cost-effective.
What are my options here? I'd like the images to be available instantly (no cron jobs/queues)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 PHP 通过 FTP 创建目录,这样就不会成为问题。
You can create directories over FTP with PHP, so that should not be a showstopper.
如果您让 PHP 服务器通过 POST 上传到 S3,您可以随意命名文件。无论如何,您应该这样做,让您的用户直接上传到 S3,中间没有 PHP 代码,这对我来说听起来对安全性不利。
If you let your PHP server do the uploading to S3 via POST, you can name the files whatever you want. You should do that anyway, letting your users upload to S3 directly, without your PHP code inbetween, sounds like bad for security to me.