Both localhost and online are using Ubuntu, Apache and PHP 7.3
I and developing a website and currently have about six Rsync commands displayed on a debug-page.php. Each command has to be copied and pasted to a Terminal Command and the relevant folder is uploaded in seconds. This is far better than using FileZilla ![]()
I was hoping instead of having to copy and paste to create a link but have not been successful ![]()
Calling PHPâs exec($command); works OK with simple commands but fails when I tried Rsync. The script works OK when copyied and pasted into the Terminal Command.?
Test script:
<?php
DECLARE(STRICT_TYPES=1);
error_reporting(-1);
ini_set('display_errors', '1');
echo '<p>';
echo '<a href="?test=1"> whoami </a> ';
echo '<a href="?test=2"> date </a> ';
echo '<a href="?test=3"> Rsync </a> ';
echo '</p>';
$test = $_GET['test'] ?? NULL;
if($test):
$tmp = 'rsync -avz /var/www/example.com/fileToUpload.php -e ssh root@123.321.111.222/var/www/example.com/';
if('1' === $test) : $command = 'whoami'; endif;
if('2' === $test) : $command = 'date'; endif;
if('3' === $test) : $command = $tmp; endif;
// exec ( string $command [, array &$output [, int &$return_var ]] ) : string
$result = exec ( '"' .$command .'"', $output, $retVar);
$prn = print_r($output, TRUE);
echo $tmp = <<< ____EOT
<dl>
<dt> \$command ==> $command <dt>
<dd> <br> </dd>
<dt> \$result </dt>
<dd> $result </dd>
<dt> \$retVar </dt>
<dd> $retVar <dd>
<dt> \$output </dt>
<dd> $prn </dd>
</dl>
____EOT;
endif;
