问题
I have a script (PHP) that stores an image uploaded by a user to my server. After it is uploaded (which involves some processing) I want to move that processed file to S3.
Just to be clear, here is what I would like to achieve:
- Let user upload file to my server
- Process image (resize etc.)
- Move processed image to my S3 bucket with a specific dynamically generated name, eg. 123876542234.jpg
- Get out the address of the publicly accessible file in my S3 bucket
I have no experience with using S3 but have a strong grasp of PHP. I tried a few tutorials but none of them worked. Any help would be greatly appreciated.
回答1:
IF you download the SDK http://aws.amazon.com/sdkforphp/ they provide a few examples, and one of them is all about S3. It includes how to upload files to S3 using PHP.
回答2:
Make sure you get the newer version 2. It has a faster and more reliable HTTP layer, and uses modern concepts such as Iterators and Observers.
Here's some S3-specific documentation. https://github.com/aws/aws-sdk-php/blob/master/docs/service-s3.rst. Here's all of the other documentation. http://aws.amazon.com/documentation/sdkforphp2/
回答3:
With a strong grasp of PHP, I'd go straight to the AWS PHP SDK, which contains all the documentation you need to send a given file to S3 using the SDK's API: http://aws.amazon.com/sdkforphp/
回答4:
For the upload with S3, take a look at this similar topic File upload to Amazon S3 from PHP
and this posts
http://www.9lessons.info/2012/08/upload-files-to-amazon-s3-php.html http://net.tutsplus.com/tutorials/php/how-to-use-amazon-s3-php-to-dynamically-store-and-manage-files-with-ease/
Amazon doesn't charge you the bandwidth used for upload, but you may be wasting server processing time and your client's bandwidth.
I suggest you to use plupload, it is free and does all the image manipulation on the client side if you want to.
http://www.plupload.com/
HTH
来源:https://stackoverflow.com/questions/15170895/moving-a-file-stored-locally-to-amazon-s3