Give User Access Specific Database (MySQL)

Ok first we need to create user, login user as root to your MySQL

> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

after create user, create database then give privileges to the user

> CREATE DATABASE new_database;
> GRANT ALL PRIVILEGES ON new_database.* TO 'newuser'@'localhost';

then flush privileges

> FLUSH PRIVILEGES;

OK DONE.

source: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Can’t Write/Access Directory – Centos 7

type this command into your shell

# SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R
 
# Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R

source: https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

thx.

Zip PDF File Into One (PHP)

function create_zip($files = array(),$destination = '',$overwrite = false) {
    if(file_exists($destination) && !$overwrite) { return false; }
    $valid_files = array();
    if(is_array($files)) {
        foreach($files as $file) {
            if(file_exists($file)) {
                $valid_files[] = $file;
            }
        }
    }
    if(count($valid_files)) {
        $zip = new ZipArchive();
        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
            return false;
        }
        foreach($valid_files as $file) {
            $zip->addFile($file,$file);
        }
        $zip->close();
        return file_exists($destination);
    }
    else
    {
        return false;
    }
}

$dir = 'file/';
$a = scandir($dir);
$searchForName = 'FI160009';
$files_to_zip = array();
foreach ($a as $key => $v) {
    if (strpos($v, $searchForName) !== false) {
        $files_to_zip[] = $dir.'/'.$v;
    } 
}

$result = create_zip($files_to_zip,$searchForName.'.zip', true);

then check on your directory. done