Created
March 21, 2019 13:12
-
-
Save Inigovd/b09eadf1bed2489be79fbc95f48261fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<input type="file" @change="onFileChange" accept=".csv"> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: "Upload", | |
methods: { | |
onFileChange(event) { | |
var formData = new FormData() | |
formData.append("file", event.target.files[0]) | |
this.$http.post('/your-api-url-here', formData, { | |
headers: { | |
'Content-Type': 'multipart/form-data' | |
} | |
}).then((response) => { | |
// Handle response | |
}) | |
} | |
} | |
} | |
</script> | |
<?php | |
// In your laravel controller | |
function upload(Request $request) | |
{ | |
// Save file | |
$file = $request->file('file'); | |
$name = 'your-file-name.ext'; | |
$file->move(public_path() . '/uploads/', $name); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment