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);