开发者

Using PHP and Curl to POST an entire folder to another Server

开发者 https://www.devze.com 2023-01-05 14:51 出处:网络
What is the best way using PHP 开发者_JAVA技巧and Curl to POST an entire folder to another server.you can:

What is the best way using PHP 开发者_JAVA技巧and Curl to POST an entire folder to another server.


you can:

  • post all files in the directory consequently

  • zip the directory and post the archive


$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.

0

精彩评论

暂无评论...
验证码 换一张
取 消