Skip to content

Instantly share code, notes, and snippets.

@mitrallex
mitrallex / FileController.php
Last active July 27, 2018 18:09
laravel-file-hosting-refactor
<?php
class FileController extends Controller
{
/**
* Constructor
*/
public function __construct()
{
$this->middleware('auth');
}
@mitrallex
mitrallex / main.blade.php
Last active July 27, 2018 18:06
laravel-file-hosting-refactor
<img v-if="file === editingFile" src="" :src="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + savedFile.type + '/' + savedFile.name + '.' + savedFile.extension" :alt="file.name">
<img v-if="file !== editingFile" src="" :src="'{{ asset('storage/' . Auth::user()->name . '_' . Auth::id()) }}' + '/' + file.type + '/' + file.name + '.' + file.extension" :alt="file.name">
<style type="text/css">@import url("style.css");</style>
<style type="text/css">@import url("bulma.min.css");</style>
<?php
// Define main variables
$im_folders = array('images', 'images10', 'images35', 'images_t', 'images_hq');
/**
* Select server
* @return array Server params
body,
html {
font-family: Arial;
font-size: 13px;
}
.container {
margin: 10px !important;
}
<?php
if (!function_exists("readline")) {
/**
* Reads a single line from the user
* @param string $prompt You may specify a string with which to prompt the user
* @return string Single string from the user
*/
function readline($prompt = null) {
if ($prompt){
@mitrallex
mitrallex / endEditing
Last active February 5, 2018 20:37
laravel-file-hosting
endEditing(file) {
this.editingFile = {};
let formData = new FormData();
formData.append('name', file.name);
formData.append('type', file.type);
formData.append('extension', file.extension);
axios.post('files/edit/' + file.id, formData)
.then(response => {
@mitrallex
mitrallex / deleteFile
Created February 5, 2018 12:00
laravel-file-hosting
deleteFile() {
axios.post('files/delete/' + this.deletingFile.id)
.then(response => {
this.showNotification('File successfully deleted!', true);
this.fetchFile(this.activeTab, this.pagination.current_page);
})
.catch(error => {
this.errors = error.response.data.errors();
this.showNotification('Something went wrong! Please try again later.', false);
this.fetchFile(this.activeTab, this.pagination.current_page);
@mitrallex
mitrallex / submitForm
Created February 5, 2018 11:59
laravel-file-hosting
submitForm() {
this.formData = new FormData();
this.formData.append('name', this.fileName);
this.formData.append('file', this.attachment);
axios.post('files/add', this.formData, {headers: {'Content-Type': 'multipart/form-data'}})
.then(response => {
this.resetForm();
this.showNotification('File successfully upload!', true);
this.fetchFile(this.activeTab);
@mitrallex
mitrallex / getFiles
Created February 5, 2018 11:57
laravel-file-hosting
getFiles(type) {
this.setActive(type);
this.fetchFile(type);
if (this.activeTab === 'video') {
this.isVideo = true;
} else {
this.isVideo = false;
}
},
@mitrallex
mitrallex / fetchFile
Created February 5, 2018 11:57
laravel-file-hosting
fetchFile(type, page) {
this.loading = true;
axios.get('files/' + type + '?page=' + page).then(result => {
this.loading = false;
this.files = result.data.data.data;
this.pagination = result.data.pagination;
}).catch(error => {
console.log(error);
this.loading = false;
});