Javascript 如何从vue js app将文件上传到laravel的本地公共磁盘?
您好,我想从vue js应用程序将该文件上传到laravel的本地公共目录中,并仅在提交表单时将唯一名称发送到mysql。但我不知道如何使用js来实现这一点Javascript 如何从vue js app将文件上传到laravel的本地公共磁盘?,javascript,laravel,file,vue.js,asyncfileupload,Javascript,Laravel,File,Vue.js,Asyncfileupload,您好,我想从vue js应用程序将该文件上传到laravel的本地公共目录中,并仅在提交表单时将唯一名称发送到mysql。但我不知道如何使用js来实现这一点 // template tag <input type="file" @change="uploadFile" > // methods on Vue Js app methods: { uploadFile(){ // logic to upload the file in l
// template tag
<input type="file" @change="uploadFile" >
// methods on Vue Js app
methods: {
uploadFile(){
// logic to upload the file in local public disk and only send the unique name to mysql
}
}
我认为你还是应该为它制作一个API。并通过api上传 我这里有一个代码,也许能帮上忙。只需将其添加到laravel控制器中即可
$user = User::find($request->user_id);
if ($request->file('profile_image') !== null) {
$imageProfile = $request->file('profile_image');
$imageProfileSanitizedName = time() . $imageProfile->getClientOriginalName();
$imageProfile->move("images/", $imageProfileSanitizedName);
$user->image = $imageProfileSanitizedName;
}
$user->save();
此函数
$imageProfile->moveimages/,$imageProfileSanitizedName;将移到
laravel项目的public/images目录
我添加了时间函数,这样图像文件将是唯一的
不要忘记在vuejs方法中使用axios中的formData。我认为您仍然应该为此制作一个API。并通过api上传 我这里有一个代码,也许能帮上忙。只需将其添加到laravel控制器中即可
$user = User::find($request->user_id);
if ($request->file('profile_image') !== null) {
$imageProfile = $request->file('profile_image');
$imageProfileSanitizedName = time() . $imageProfile->getClientOriginalName();
$imageProfile->move("images/", $imageProfileSanitizedName);
$user->image = $imageProfileSanitizedName;
}
$user->save();
此函数
$imageProfile->moveimages/,$imageProfileSanitizedName;将移到
laravel项目的public/images目录
我添加了时间函数,这样图像文件将是唯一的
别忘了在vuejs方法中使用axios中的formData。谢谢您的帮助,我知道我只能用您解释的服务器端代码移动文件感谢您的帮助我知道我只能用您解释的服务器端代码移动文件