I am using CURL to post to an form on a different server. The form has the ability to upload a file as well. I have read somewhere that it’s possible to do this using CURL. Here’s the script I am using, but it doesn’t seem to be uploading the file to the other server.
I have already seen this thread and I guess I need it to do something slightly different.
I have an upload form, which is posting to another upload form on another server (if that makes sense??). The user uploads the file on my site, and it is automatically then submitted to another form on another site. Is this possible?
Note: Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data, while passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
This was probably why the remote server did not recognise the uploaded file before. So I am now passing an array to CURLOPT_POSTFIELDS. I think it’s recognising the file now, because when I pass the $_FILES[‘myfile’][‘tmp_name’] I get a blank page.
Any idea how to debug why I am getting a blank page?
The code you posted does not send the file data, merely the name.
You need to send the data specifying multipart/form-data, build the content manually. Check the headers and content sent to the remote server when you perform the operation ‘on-site’ so to speak, then use code to reproduce this.