How to list all files in a directory and read each of them in PHP

This code snippet is useful to me when I need to read all files inside a directory and showing it on web browser in PHP:

<?php
header('Content-type: text/plain; charset=utf-8');
$dir = "1"; //this is a folder containing files we want to read.
$files = scandir("$dir");
foreach($files as $key=>$value){
	if(!in_array($value, array(".", ".."))){
		echo "Found this file: " . $value . "<br>Begin reading...";
		$currentfile = fopen($dir . "/" . $value, "r") or die("Unable to read the file!");
		echo fread($currentfile, filesize($dir . "/" . $value));
		echo "Reading finished.";
	}
}

Switchable “Camera Follows a Player” accross mutliple scenes in Unity

This is a Unity package file, if you download it and import it on your empty Unity project, you will see a demonstration about a camera that follows an object, and this camera (it’s position) is switchable, you can click a button to switch between multiple camera positions and angles. Plus there are two buttons to open two empty scenes, but when you open it the player object and cameras will be there too.

The purpose of this demonstration is to show you how an object like player, camera, etc can be used on multiple scenes without reloading them in each scenes, by adding one line script to make those objects undestroyable when you change scenes.

How to switch between camera positions and angles in Unity by C# script

The script inside this package allows you to switch between camera positions so you can switch between camera angles and positions easily with single click button.

In this example, there were 3 camera positions that we can switch between them. In this video I also tried to add another camera position (the 4th position).

You will also be able to adjust camera switching speed to be fast or slow.

One line PHP code to remove characters except numbers and letters

I found this few lines of PHP script useful to sanitize user input, it removes characters except numbers and letters:

$clean_code = preg_replace('/[^\w]/', '', $string);

Or this one:

$clean_code = preg_replace('/[^a-zA-Z0-9]/', '', $string);

Original post is here: https://coderwall.com/p/bn47ka/remove-all-characters-except-letters-and-numbers-in-php

HealthCon Responsive HTML5 Website Template

A responsive and excellence HTML5 website with slide-able style menu and sub menu feature for both mobile and desktop version.

Below image is the desktop version of this website template:

You can view it in action in this video:

Get this template from this link: https://creativeshop.ciihuy.com/product/healthcon-responsive-html5-website-template/

How to send POST request to another website from a PHP script

Let’s say we have a website like somewebsite.com and there is an input form, but we don’t want to submit that form from that website, instead we send POST request to that page from another website. Here is a handy PHP script to do so:

<?php

$url = 'https://somewebsite.com/';
$data = array('key1' => 'value1', 'key2' => 'vaue2');

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

?>

Save Android Webview Content as PDF File

Hello everybody!

What you are seeing here is an Android app that shows a local html file inside a Web View.

Then on top of the web view there is a button to save web view contents as a pdf file.

Pdf file is saved localy after you tapped the button and you can open it using your favorite pdf viewer app in your phone.

How to make objects facing towards player in Unity

Some of elements in our game probably need to always face towards the player or player’s camera.

With this script we can make any object that this script attached on it, to look at a specific object, like player object or a camera.

How to open WebP images in Photoshop – WebP Photoshop Plugin

Finally this plugin solved my problem. Usually when I got a webp images downloaded from internet, I take a screenshot of the image and copy and paste it inside Photoshop.

But lucky me I found this plugin from this link: https://endurtech.com/how-to-open-webp-files-in-adobe-photoshop/

Extract the file, and find 32 or 64 plugin file, copy and paste it on your Photoshop plugin directory. Enjoy!