我试图通过我的网络服务器(RasPi)上的网站重命名文件。这一切都通过jquery ajax请求,它的工作原理。文件成功重命名但由于某种原因我在浏览器控制台中收到错误。
当我尝试从pi上的webbrowser重命名文件时,它的工作没有任何错误。
JS Part
$.ajax({
url: 'rsrc/php/filemanager.php',
type: 'get',
data: {'action': 'renameFile', 'path': $folderpath, 'oldfilename': $oldfilename, 'newfilename': $newfilename},
success: function(answer) {
console.log(answer);
if(answer == "OK") {
location.reload();
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError: " + err);
}
});
PHP
if ($_GET['action'] == 'renameFile') {
$subfolderPath = $_GET['path'];
$oldfilename = $_GET['oldfilename'];
$newfilename = $_GET['newfilename'];
$preview_oldfilename = substr($oldfilename, 0, strrpos($oldfilename, ".")) . ".jpg";
$preview_newfilename = substr($newfilename, 0, strrpos($newfilename, ".")) . ".jpg";
$renameOldPath = $uploadfolder . $subfolderPath . $oldfilename;
$renameNewPath = $uploadfolder . $subfolderPath . $newfilename;
$renamePreviewOldPath = $uploadpreviewfolder . $subfolderPath . $preview_oldfilename;
$renamePreviewNewPath = $uploadpreviewfolder . $subfolderPath . $preview_newfilename;
echo $renameOldPath;
//To be revisited: Empty Error
$firstRename = rename($renameOldPath, $renameNewPath);
$secondRename = rename($renamePreviewOldPath, $renamePreviewNewPath);
if($firstRename == true && $secondRename == true) {
echo "OK";
} else {
echo "NO";
}
}
抱歉这里的格式不正确。即使我只是打印出路径并手动使用mv它工作得很好。当我使用exec时,我仍然得到相同的错误。知道是什么原因引起的吗?到目前为止,我在Chrome和Firefox上试过它