What is the best way using PHP and Curl to POST an entire folder to another server.
A:
you can:
post all files in the directory consequently
zip the directory and post the archive
kgb
2010-06-29 13:32:44
I think you mean consecutively http://www.merriam-webster.com/netdict/consecutively
Matt S
2010-06-29 14:15:04
A:
$srcdir = '/source/directory/';
$dh = opendir($srcdir);
$c = curl_init();
curl_setopt($c, ....); // set necesarry curl options to specify target url, etc...
while($file = readdir($dh)) {
if (!is_file($srcdir . $file)) {
continue; // skip non-files, like directories
}
curl_setopt($c, CURLOPT_POSTFIELDS, "file=@{$srcdir}{$file}");
curl_exec($c);
}
closedir($dh);
That'd be the basics. You'd want some error handling in there, to make sure the source file is readable, to make sure the upload succeeds, etc.. The full set of CURLOPT constants are documented here.
Marc B
2010-06-29 17:16:25
What about posting multiple files in one request? Can you post an array of files in one request?
Chris Muench
2010-07-02 16:52:58
Marc B
2010-07-03 13:34:24