Пример #1
0
function upload_static_file($bucket, $remote_name, $local_name, $args)
{
    global $AMZ_KEY, $AMZ_SECRET;
    // Prepare any additional headers...
    $headers = array();
    if ($args->flag('x')) {
        $headers['Expires'] = date('D, j M Y H:i:s', time() + 86400 * 365 * 10) . ' GMT';
        // 10 years
    }
    // Version the file?
    if ($args->flag('version')) {
        $info = pathinfo($remote_name);
        $dir = $info['dirname'] . '/';
        if ($dir == './') {
            $dir = '';
        }
        $remote_name = $dir . $info['filename'] . $args->flag('version') . '.' . $info['extension'];
    } elseif ($args->flag('t')) {
        $info = pathinfo($remote_name);
        $dir = $info['dirname'] . '/';
        if ($dir == './') {
            $dir = '';
        }
        $remote_name = $dir . $info['filename'] . '.' . date('YmdHis') . '.' . $info['extension'];
    }
    // Begin the upload proccess
    $s3 = new S3($AMZ_KEY, $AMZ_SECRET);
    // Should we check to see if the file has already been uploaded?
    $ok_to_upload = true;
    if ($args->flag('c')) {
        $info = $s3->getObjectInfo($bucket, $remote_name);
        if (substr($info['ETag'], 1, -2) == md5_file($local_name)) {
            $ok_to_upload = false;
            echo "Skipping (MD5 match): http://{$bucket}.s3.amazonaws.com/{$remote_name}\n";
        }
    }
    // Actually upload the file...
    if ($ok_to_upload) {
        if ($s3->uploadFile($bucket, $remote_name, $local_name, true, $headers)) {
            echo "http://{$bucket}.s3.amazonaws.com/{$remote_name}\n";
        } else {
            trigger_error("Unable to upload '{$local_name}' to '{$remote_name}'\n", E_USER_ERROR);
        }
    }
    // Upload the gzipped version...
    if ($args->flag('z')) {
        $info = pathinfo($remote_name);
        $dir = $info['dirname'] . '/';
        if ($dir == './') {
            $dir = '';
        }
        $remote_name = $dir . $info['filename'] . '.gz.' . $info['extension'];
        $gzname = tempnam('/tmp', 's3up') . '.' . $info['extension'];
        shell_exec(sprintf('gzip -c %s > %s', escapeshellarg($local_name), $gzname));
        $headers['Content-Encoding'] = 'gzip';
        // Should we check to see if the file has already been uploaded?
        $ok_to_upload = true;
        if ($args->flag('c')) {
            $info = $s3->getObjectInfo($bucket, $remote_name);
            if (substr($info['ETag'], 1, -2) == md5_file($local_name)) {
                $ok_to_upload = false;
                echo "Skipping (MD5 match): http://{$bucket}.s3.amazonaws.com/{$remote_name}\n";
            }
        }
        // Actually upload the file...
        if ($ok_to_upload) {
            if ($s3->uploadFile($bucket, $remote_name, $gzname, true, $headers)) {
                echo "http://{$bucket}.s3.amazonaws.com/{$remote_name}\n";
            } else {
                trigger_error("Unable to upload '{$local_name}' to '{$remote_name}' (gzip version)\n", E_USER_ERROR);
            }
        }
    }
}
Пример #2
0
 public static function uploadTempFile($file_path, $ext, $mime)
 {
     $tmp_name = Random::string(16) . ".{$ext}";
     S3::uploadFile(static::TEMP_DIR . $tmp_name, $file_path, $mime, 'private');
     return $tmp_name;
 }
Пример #3
0
        $v = new Version();
        $v->app_id = $app->id;
        $v->version_number = $_POST['version_number'];
        $v->human_version = $_POST['human_version'];
        $v->release_notes = $_POST['release_notes'];
        $v->dt = dater();
        $v->downloads = 0;
        $v->filesize = filesize($_FILES['file']['tmp_name']);
        $v->signature = sign_file($_FILES['file']['tmp_name'], $app->sparkle_pkey);
        $object = strtolower(preg_replace('/[^a-zA-Z0-9]/', '', $app->name)) . "_" . $v->version_number . "." . substr($_FILES['file']['name'], -3);
        $v->url = slash($app->s3path) . $object;
        $info = parse_url($app->s3path);
        $object = ltrim(slash($info['path']) . $object, '/');
        chmod($_FILES['file']['tmp_name'], 0755);
        $s3 = new S3($app->s3key, $app->s3pkey);
        $s3->uploadFile($app->s3bucket, $object, $_FILES['file']['tmp_name'], true);
        $v->insert();
        redirect('versions.php?id=' . $app->id);
    } else {
        $version_number = $_POST['version_number'];
        $human_version = $_POST['human_version'];
        $release_notes = $_POST['release_notes'];
    }
} else {
    $version_number = '';
    $human_version = '';
    $release_notes = '';
}
function sign_file($filename, $keydata)
{
    $binary_hash = shell_exec('openssl dgst -sha1 -binary < ' . $filename);
Пример #4
0
 // upload to S3 only if its configured.
 if (!empty($app->s3path)) {
     // END adib 7-Apr-2010 12:36
     $v->url = slash($app->s3path) . $object;
     $info = parse_url($app->s3path);
     $object = slash($info['path']) . $object;
     // BEGIN adib 7-Apr-2010 10:59
     //chmod($_FILES['file']['tmp_name'], 0755);
     if (is_uploaded_file($uploadedFile['tmp_name'])) {
         chmod($uploadedFile['tmp_name'], 0755);
     }
     // END adib 7-Apr-2010 10:59
     $s3 = new S3($app->s3key, $app->s3pkey);
     // BEGIN adib 7-Apr-2010 11:00
     //$s3->uploadFile($app->s3bucket, $object, $_FILES['file']['tmp_name'], true);
     $s3->uploadFile($app->s3bucket, $object, $uploadedFile['tmp_name'], true);
     // END adib 7-Apr-2010 11:00
     // BEGIN adib 7-Apr-2010 12:37
 } else {
     if (!empty($Config->downloadBaseFolder)) {
         // upload into a folder local to the web server.
         $downloadFolder = $Config->downloadBaseFolder . '/' . $app->id;
         if (!is_dir($downloadFolder)) {
             if (!mkdir($downloadFolder, 0775, true)) {
                 die('Could not create download folder ' . $downloadFolder);
             }
         }
         $destinationFile = $downloadFolder . '/' . $object;
         if (is_uploaded_file($uploadedFile['tmp_name'])) {
             move_uploaded_file($uploadedFile['tmp_name'], $destinationFile);
         } else {