Post a dynamic file using curl

I’m working on a small script that will use the post method to send a file and a couple other parameters to an external form. In order to post the form I’m using curl. I’ve succeed in sending a post command when using a static file. Now however, I need to figure out how to integrate it using a dyanmically cretaed file at a specified url.

This is what I have, however I don’t think the file is being handled correctly. I’m not sure exactly how to handle it because it is not a physical file so much as a script location which generates a file.

$fileurl = "http://www.ascriptonmywebsite";
$file = file($fileurl);
$url = '';
$area = "test";
$params = array(
     'fname' => "@$file"

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

If the file doesn’t exist, the POST protocol won’t be able to access the file.
Given that, you’ll need to create a temporary file so that POST can successfully send it.

Ok that makes sense and I’ve been thinking it over the last couple of days. I’m trying to figure out how to handle the data and how to create a temporary physical file to load.

When you load the script in the browser it creates the xml file and prompts you to download it. I’m a little confused on how to actually save the file. Given the url of the script what methods do I need to use to save the file. I’ve looked into fopen/fwrite a little bit but I’m not sure how to integrate them with this idea.