diff --git a/.gitignore b/.gitignore index 0f7df0f..90dd474 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /node_modules /public/hot /public/storage +/public/upload/* /storage/*.key /vendor .env diff --git a/app/Http/Controllers/Upload.php b/app/Http/Controllers/Upload.php index cd636ba..076ff83 100644 --- a/app/Http/Controllers/Upload.php +++ b/app/Http/Controllers/Upload.php @@ -9,49 +9,49 @@ class Upload extends Controller public function index(){ return view('index'); } - + public function uploadFile(Request $request){ - + if ($request->input('submit') != null ){ - + $file = $request->file('file'); - + // File Details $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $tempPath = $file->getRealPath(); $fileSize = $file->getSize(); $mimeType = $file->getMimeType(); - + // Valid File Extensions $valid_extension = array("jpg","jpeg","png"); - + // 2MB in Bytes $maxFileSize = 2097152; - + // Check file extension if(in_array(strtolower($extension),$valid_extension)){ - + // Check file size if($fileSize <= $maxFileSize){ - + // File upload location - $location = 'images'; - + $location = 'upload/images'; + // Upload file $file->move($location,$filename); - - Session::flash('message','Upload Successful.'); + + echo 'Upload Successful.'; }else{ - Session::flash('message','File too large. File must be less than 2MB.'); + echo 'File too large. File must be less than 2MB.'; } - + }else{ - Session::flash('message','Invalid File Extension.'); + echo 'message Invalid File Extension.'; } - + } - + // Redirect to index echo "OK"; } diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index a31f552..87983d5 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -62,7 +62,7 @@ } - + @@ -87,7 +87,7 @@
+