<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FileManager extends Controller
{
	private $trailPath;

	public function __construct(){
		$this->trailPath = env('PUBLIC_PATH');
	}
	
	public function fileUploaded($request){
		if(empty($_FILES)) {
			return false;
		}
		$file = $_FILES['image'];
		if(!file_exists($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])){
			return false;
		}   
		return true;
	}

	public function moveFile($request,$path){
		$image = $request->file('image');
		$imageName = 'amgroup-'.time().'.'.$image->getClientOriginalExtension();
		$destination = $this->trailPath.$path;
		$image->move($destination,$imageName);
		return $imageName;
	}
}
