在本地机器上它是工作文件,但在AWS上它不是工作**本地机器上的路径= 'sitemap.xml'**在AWS服务器= '/var/www/html/sitemap.xml'
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute cURL request
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
// Close cURL session
curl_close($ch);
// Handle response
if ($response) {
$xml = simplexml_load_file('/var/www/html/sitemap.xml');
unset($xml->url);
$urlElement = $xml->addChild('url');
$urlElement->addChild('priority','1.0');
$urlElement->addChild('loc', 'base url');
$urlElement->addChild('lastmod', date('Y-m-d'));
$blogUrls = json_decode($response,true);
for ($i = 0; $i < count($blogUrls['DATA'][0]); $i++) {
// print_r($blogUrls['DATA'][0][0]['URL']) . '<br>';
if ($blogUrls['DATA'][0] && $blogUrls['DATA'][0][$i] && $blogUrls['DATA'][0][$i]['URL']) {
$urlElement = $xml->addChild('url');
$urlElement->addChild('priority','0.9');
$urlElement->addChild('loc', 'baseUrl'.$blogUrls['DATA'][0][$i]['URL']);
$urlElement->addChild('lastmod', $blogUrls['DATA'][0][$i]['DATE']);
}
}
$xml->asXML('/var/www/html/sitemap.xml');
} else {
// API call failed, handle the error
// echo 'API call failed';
}
1条答案
按热度按时间92dk7w1h1#
正如评论中所建议的,这是一个文件系统权限问题。