I know this to be true:
... you can post a file that is already on the filesystem by prefixing the filepath with "@".
However, I'm trying to POST a file with cURL that's not local. It's stored on some other URL. Let's just say this photo is Google's logo (it isn't). The URL of that is https://www.google.com/images/srpr/logo11w.png
. So I would think that you would do something like this:
$file = file("https://www.google.com/images/srpr/logo11w.png");
// some more stuff
// define POST data
$post_data = array('somekey' => 'somevalue',
'image' => '@' . $file);
However, this doesn't seem to work for whatever reason. Also, I tried using 'image' => '@' . file_get_contents($url)
. Again, that didn't work.
It looks like a way to get around this is to use a temporary file. Is this the only solution to this problem? In either case, how can I solve this problem?
You can not use any http
url for the file path at curl. You have to use local file. So first download the file into a temporary directory.
file_put_contents("/var/tmp/xyz/output.jpg", file_get_contents("https://www.google.com/images/srpr/logo11w.png"));
Then use this temporary file into your curl:
'image' => '@/var/tmp/xyz/output.jpg'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With