Skip to content

Instantly share code, notes, and snippets.

@girvan
Last active December 14, 2015 17:39
Show Gist options
  • Save girvan/5123921 to your computer and use it in GitHub Desktop.
Save girvan/5123921 to your computer and use it in GitHub Desktop.
s3 service
<?php
define('S3_PATH', '/var/www/data/s3');
define('S3_DN', 's3.exammple.com');
function _s3_check($s3_filename)
{
$cmd = sprintf("ssh %s 'ls -al %s 2>/dev/null && echo 1;';"
,S3_DN, S3_PATH . '/' . $s3_filename);
$resp = shell_exec($cmd);
return (boolean)$resp;
}
function _s3_put($src_file, $s3_filename)
{
$cmd = sprintf("ssh %s 'mkdir -p %s';"
,S3_DN, S3_PATH . '/' . dirname($s3_filename));
$resp = shell_exec($cmd);
$cmd = sprintf("rsync -azq %s %s && echo 1;",
$src_file, S3_DN . ':' . S3_PATH . '/' . $s3_filename);
$resp = shell_exec($cmd);
return (boolean)$resp;
}
function _s3_delete($s3_filename)
{
$cmd = sprintf("ssh %s 'rm %s 2>/dev/null && echo 1;';"
,S3_DN, S3_PATH . '/' . $s3_filename);
$resp = shell_exec($cmd);
return (boolean)$resp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment