Can I CURL POST files generated with PHP tmpfile?
Assuming I have an array of file descriptors created with PHP's tmpfile () function, can I send files as attachments using PHP curl?
I used to create an associative array of the form $ postdata [fieldname] = '@path_to_file', but since I can't figure out the path to the tmpfile (I only have a handle), I'm at a loss.
Motivation: I don't want to separately flush the contents of these tmpfiles from disk. I feel like the behavior of the tmpfile suits this purpose, but the curl component complicates things.
Consideration after answer: Jay's answer cleans up this, but I ran into the downside of the tmpfile transaction abort: the "cleanup" behavior is skipped in case of FATAL or abrupt termination of the process, so manual cleanup would be necessary as a fail-safe. I don't think there is a way to bypass the filesystem traversal process and ensure that everything is cleaned up, tmpfile or not.
source to share
Check out: http://us.php.net/manual/en/function.stream-get-meta-data.php
You can do the following:
$t = tmpfile();
$a = stream_get_meta_data($t);
$filename = $a['uri'];
This question is similar to: Getting a filename (or deleting a file) using a file descriptor
source to share