我有一个应用程序,我使用laravel作为我的后端来制作API,我使用react作为我的前端。因此,在我的React前端,我设法获得文件,这是在.txt使用axios和处理该文件,并保存到数据库。现在它来后,处理该文件,然后它应该在以前的目录中删除,并移动到其他目录,所以我的问题是,我如何才能移动该文件?
下面是我的代码:
axios
.get("docuin/incoming.xml", {
"Content-Type": "application/xml; charset=utf-8",
})
.then((response) => {
var xml = new XMLParser().parseFromString(response.data);
var from = xml.getElementsByTagName("ID")[0].value;
//from here i can send to DB using post axios,after sucessful sent now it should move into "docout/outgoing.xml"
});
我试图通过axios邮政发送它,但带来的错误。
1条答案
按热度按时间yrdbyhpb1#
为了在应用程序中将文件从一个目录移动到另一个目录,您必须使用服务器端语言,如PHP(在您的情况下,Laravel)来处理文件操作。
React本身不能直接执行文件系统操作。
1.首先,你必须创建一个路由来处理Laravel项目中的文件移动操作。
例如,在routes/api.php文件中,添加以下路由:
1.使用此命令创建新控制器。
1.在FileController的moveFile函数中,您可以添加如下功能。
1.在你的React代码中,你可以处理来自Laravel后端的响应。
您必须在Laravel应用程序中正确配置文件路径和目录,以确保文件移动到正确的位置。