I have a little problem here, how can I say cURL specifically for attaching a file to a request?
If I upload a file using cURL, then the general method is to attach it as part of a POST data array with a value having an @ in front of it, for example:
CURLOPT_POSTFIELDS=>array('my-file'=>'@my-file.txt')
This will obviously work, but I have two problems:
- What if it is not a file that I upload? What if my POST value is actually "@ my-file.txt" and it is trying to upload the file instead? This creates a loophole desperately trying to avoid.
- How to download a file from a url? Should I download it, save it in a temporary folder and then attach it to @ from this temporary folder? Why can't I give cURL only the content that I want to use as a file?
cURL CURLOPT_INFILE is not an option, as it will not be displayed as part of the $ _FILES array.
It seems that such a loophole in cURL depends on the @ symbol in the value of the POST field. Is there any way around this? Why is there no CURLOPT_FILEFIELDS array? The cURL command line has a separate flag for this (-F), but for some reason I don't see it as an option in PHP.
Any help would be greatly appreciated, thanks!
source
share