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 = 'upload/images'; $backupdir = Carbon::now()->format('Y/m/d'); $backupdir = 'upload/images/backup/' + $backupdir; $bckfile = Carbon::now()->format('Hi'); $bckfile = $bckfile + '.jpg'; // Upload file $file->copy($backupdir,$bckfile); $file->move($location,$filename); echo 'Upload Successful.'; }else{ echo 'File too large. File must be less than 2MB.'; } }else{ echo 'message Invalid File Extension.'; } } // Redirect to index echo "OK"; } }