runcloud use two projects sharing the same media folder

If you have a chance using symlink in your project. E.g your media folder. You might be using a symlink to reference the same media directory.

When I deploy my project to live. I keep hitting `Cannot save image intervention image. NotWritableException in Image.php line 138`

I am sure I am using the same owner for both directories. However it kind of weird to having this error message.

Then I started to trace the path. I tested with andFile::isDirectory File::iswritable. Then I was having open_basedir restriction in effect. File(/) is not within the allowed path(s):

Then this made me proceed to next checking.Finally, I found out this OPEN_BASEDIR issue.

In runcloud they had provided OPEN_BASEDIR for security purpose.

So what you have to do is include your another project repo into. And they have warned you about the risk. Make sure you know what you are doing.

PHP Round Up to nearest Array

//array list
$array = array(1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 150, 250, 300, 350, 400, 450, 500, 600, 700, 800, 900, 1000);

//array round up function
function getArrayRoundUp($array, $number) {

sort($array);
foreach ($array as $a) {
if ($a >= $number) return $a;
}
return end($array);
}

//assume this is the value
$value = 904.5;

$nearest = getArrayRoundUp($array, $value);

//the expect result will be 1000
echo $nearest;

 

php rename file extension

When come to Linux it is case sensitive. How do you set all your file extension in the same case.

Below is the code how I rename the file extension all from .JPG (does not matter what is the original) to .jpg

<?php


function replace_extension($filename, $new_extension) {
     $info = pathinfo($filename);

    $newname = $info['filename'] . '.' . $new_extension;
    rename('/home/image/'.$filename, '/home/image/'.$newname);
    return $newname;

}

$dir = '/home/image';
$files = scandir($dir);

//print_r($files);

foreach($files as $key => $file)
{
     echo replace_extension($file, 'jpg');
    echo "<br />";
}

 

 

 

Install PHPUnit in Windows

How to install PHPUnit in Windows

prerequisites

1. PHP installed. PHPUnit 4.1 requires PHP 5.3.3; using the latest version of PHP is highly recommended.

2. Set your PHP folder (e.g C:phpbin) to your Environment Variable. Thus, you can run php in your command prompt without full path

 

Step to install PHPUnit

1. Download from the PHPunit website. https://phar.phpunit.de/phpunit.phar, if you PC support wget you can use the following command to download the phpunit.phar to your php bin folder.

wget https://phar.phpunit.de/phpunit.phar

My case it will located in C:phpbinphpunit.phar

2. Create a .bat file, you can create a .txt file rename it to .bat later. Inside the content paste these in


@echo off
php "%~dp0phpunit.phar" %*

Rename your txt file to .bat


C:phpbinphpunit.bat

Access to your Command prompt, try enter the command phpunit, you should able to see the below result:
phpunit

Enjoy your testing!

PS: No color in your testing output in command prompt? Read the next post to enable it!