Monthly archives: October, 2018

Google reCaptcha V2 & V3 javascript demo and php example code

<?php // google recaptcha v2 $siteKey = ‘siteKey222’; $secret = ‘secret2222’; // google recaptcha v3 $siteKey_v3 = ‘siteKey333’; $secret_v3 = ‘secret3333’; function getRrecaptchaResult($secret_key, $g_recaptcha_response) { $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_URL => ‘https://www.google.com/recaptcha/api/siteverify’, CURLOPT_POSTFIELDS => [ ‘secret’ => $secret_key, ‘response’ => $g_recaptcha_response, ‘remoteip’ => $_SERVER[‘REMOTE_ADDR’] ] ]); $response = …

Example for get value from ngNoForm and combine a search in Angular

ngNoForm: Create New Extractee: All {{e.name}} Status: All Open Finalised .ts index(): let f = document.getElementById(‘search_form’); if (f) { if (f.status.value != ” && f.laravel_id.value != ”) { params = params.set(‘search’, ‘status:’ + f.status.value + ‘;laravel_id:’ + f.laravel_id.value) .set(‘searchFields’, ‘status:=;laravel_id:=’) .set(‘searchJoin’, ‘and’); } else if (f.laravel_id.value != ”) { params = params.set(‘search’, f.laravel_id.value) .set(‘searchFields’, ‘laravel_id:=’); …

How to select all/trigger/unselect checkbox in Angular without use FormArray and ngModel

.html: …… {{item.site.name}} .ts: export interface NewXxxModel extends XxxModel { checkbox_value?: boolean; } …. not_assigned_tasks: NewXxxModel[]; new_tasks_ary: Array = []; …. triggerAll(tasks: string, event: any) { if (tasks == ‘not_assigned_tasks’) { this.new_tasks_ary = []; for (var i = 0; i < this.not_assigned_tasks.length; i++) { if (event && event.target.checked == false) { this.not_assigned_tasks[i].checkbox_value = false; } ...

How to upload multiple files via Angular and reset file input

<!– upload files –> <divclass=”input-group mb-3″ *ngIf=”declaration_status==’Open'”> <divclass=”input-group-prepend”> <spanclass=”input-group-text”id=”basic-addon1″>Upload Attachments</span> </div> <input class=”form-control” #chooseFileInput (change)=”fileChange($event)” type=”file”name=”file” multiple placeholder=”Upload files”accept=”.png,.gif,.jpeg,.pdf,.txt,.csv,.doc,.zip,.gz,.rar”id=”choose_file”> <span *ngIf=”uploading” class=”input-group-text”><i class=”fa fa-spinner fa-spin mr-3 ml-2″aria-hidden=”true”></i> Uploading …</span> </div> ts: fileChange(event: any) { let formData = new FormData(); let fileList: FileList = event.target.files; for (let i = 0; i < fileList.length; i++) { formData.append(‘files[]’, …

How to download/display bolb/bytea file from database use Laravel

We should use raw query instead of eloquent of laravel: $uploadedFile = $this->uploadedFileRepository->findWithoutFail($id); $f = \DB::table(‘uploaded_files’) ->selectRaw(‘*’) ->where(‘id’, ‘=’, $id) ->first(); $file_bytea = stream_get_contents($f->file_content); if (function_exists(‘pg_unescape_bytea’)) { $file_str = pg_unescape_bytea($file_bytea); } else { $file_str = pack(‘H*’, $file_bytea); } header(“Content-type:”.$f->mime_type); //if (strpos($f->mime_type, ‘image’) === false && strpos($f->mime_type, ‘pdf’) === false) { header(“Content-Disposition: attachment; filename=”.$f->file_name); //} echo$file_str; …