简体   繁体   English

使用PHP和Curl将整个文件夹发布到另一台服务器

[英]Using PHP and Curl to POST an entire folder to another Server

使用PHP和Curl将整个文件夹发布到另一台服务器的最佳方法是什么。

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 . 你会希望在那里处理一些错误,以确保源文件是可读的,以确保上传成功,等全套CURLOPT常数都记录在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM