I have an image resource that is manipulated with imagecopyresampled. I need to pass that image to a set of methods that expect a string input, not a resource. But I don’t need to store the file locally.
Is this the proper way:
- Store the image with
imagepngandimagejpeg - Pass string (filename) to the methods
- Destroy the stored file with
@unlink
Is that right? Seems sloppy.
Note: the image is not coming from a file upload and hence can’t be accessed with $_FILES["Filedata"]["tmp_name"]
I took a look at the Amazon S3 PHP API:
http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html#m=AmazonS3/upload_part
I assume you are using something like the
upload_partmethod that takes a stringfilename. In that case, unless you plan to modify their library, you will need to store the file to disk and pass them the filename so they can read the file and perform the upload.Besides the steps mentioned in your question you can take a look at
imagedestroyto make sure you are freeing up the memory for your image resource after it is written to disk withimagepng. And then, as you stated, you can delete your temp file withunlinkafter your upload is complete.I agree, it does seem a bit wasteful, but in this case necessary since the API doesn’t seem to provide an alternative.