当前位置: 首页>>代码示例>>PHP>>正文


PHP S3::uploadFile方法代码示例

本文整理汇总了PHP中S3::uploadFile方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::uploadFile方法的具体用法?PHP S3::uploadFile怎么用?PHP S3::uploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在S3的用法示例。


在下文中一共展示了S3::uploadFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload_static_file

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);
            }
        }
    }
}
开发者ID:gerrywastaken,项目名称:s3up,代码行数:74,代码来源:s3up.php

示例2: uploadTempFile

 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;
 }
开发者ID:kzfk,项目名称:emlauncher,代码行数:6,代码来源:Package.php

示例3: sign_file

        $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);
开发者ID:jschilli,项目名称:Shine,代码行数:31,代码来源:version-new.php

示例4: slash

 // 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 {
开发者ID:adib,项目名称:Shine,代码行数:31,代码来源:version-new.php


注:本文中的S3::uploadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。