1
我有一个简单的PHP脚本,可以扫描整个目录并上传所有文件。但我希望它也可以上传文件夹。 (并保持文件夹结构)我该怎么做?PHP cURL - 如何上传文件夹?
我的代码:
$dir = 'Test/';
$di = new RecursiveDirectoryIterator($dir);
$ch = curl_init('https://website.com');
curl_setopt($ch, CURLOPT_URL,'https://website.com');
curl_setopt($ch, CURLOPT_POST,1);
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
echo $filename;
$cFile = curl_file_create($filename);
$post = array('file'=> $cFile);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
}
curl_close ($ch);