Skip to content

Instantly share code, notes, and snippets.

@Inigovd
Created March 21, 2019 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Inigovd/b09eadf1bed2489be79fbc95f48261fe to your computer and use it in GitHub Desktop.
Save Inigovd/b09eadf1bed2489be79fbc95f48261fe to your computer and use it in GitHub Desktop.
<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