Ejemplo n.º 1
0
 /**
  * Store Upload file to S3.
  * @param CUploadedFile $uploadedFile
  * @param string $bucket The file to create the object
  * @return string url to the file.
  */
 public function store($uploadedFile, $bucket = NULL)
 {
     if ($this->config['randomPath']) {
         $filePath = $this->config['pathPrefix'] . md5(date('His')) . '/' . $uploadedFile->getName();
     } else {
         $filePath = $this->config['pathPrefix'] . $uploadedFile->getName();
     }
     if ($bucket === NULL) {
         $bucket = $this->config['defaultBucket'];
     }
     /** @var CFResponse $result */
     $result = $this->s3->create_object($bucket, $filePath, array('fileUpload' => $uploadedFile->getTempName(), 'acl' => $this->config['defaultACL']));
     if ($result->isOk()) {
         return urldecode($this->s3->get_object_url($bucket, $filePath));
     } else {
         Yii::log("STATUS:" . $result->status . "\nHEDAER:" . $result->header . "\nBODY:" . $result->body, CLogger::LEVEL_ERROR, "application");
         throw new CException($result->status);
     }
 }
Ejemplo n.º 2
0
    mysql_close($conn);
    $newFileName = md5($username . $deviceID) . "_";
    $s3 = new AmazonS3();
    $bucket = 'com.sanchitkarve.tb.usor';
    $response = $s3->get_object_list($bucket);
    $userFiles = array();
    $foundFiles = false;
    foreach ($response as $item) {
        if (startsWith($item, $newFileName)) {
            $userfiles[] = $item;
            $foundFiles = true;
        }
    }
    // create cloudfront link if possible
    $urls = "";
    //print_r($response);
    if ($foundFiles) {
        foreach ($userfiles as $uitem) {
            $link = $s3->get_object_url($bucket, $uitem, '10 minutes');
            // replace domain with cloudfront and put them in urls
            $urls .= $link . " ";
        }
        //remove last space
        $urls = trim($urls);
        echo $urls;
    } else {
        echo "NOFILES";
    }
} else {
    echo "Error: Not all parameters set.";
}
Ejemplo n.º 3
0
 /**
  * Get the S3 absolute URL for the specified path
  *
  * @param string $path The path by which to grab the URL
  * @param string $expires The time in which the URL expires
  * @return bool|mixed|string
  */
 public function getFileUrl($path, $expires = null)
 {
     return $this->s3->get_object_url($this->bucket, $path, $expires);
 }
        $s3->batch()->create_object($bucket, $filename, array('fileUpload' => $file));
    }
    /* Execute our queue of batched requests. This may take a few seconds to a
       few minutes depending on the size of the files and how fast your upload
       speeds are. */
    $file_upload_response = $s3->batch()->send();
    /* Since a batch of requests will return multiple responses, let's
       make sure they ALL came back successfully using `areOK()` (singular
       responses use `isOK()`). */
    if ($file_upload_response->areOK()) {
        // Loop through the individual filenames
        foreach ($individual_filenames as $filename) {
            /* Display a URL for each of the files we uploaded. Since uploads default to
               private (you can choose to override this setting when uploading), we'll
               pre-authenticate the file URL for the next 5 minutes. */
            echo $s3->get_object_url($bucket, $filename, '5 minutes') . PHP_EOL . PHP_EOL;
        }
    }
}
/*%******************************************************************************************%*/
// HELPER FUNCTIONS
// Filters the list for only files
function filter_file_list($arr)
{
    return array_values(array_filter(array_map('file_path', $arr)));
}
// Callback used by filter_file_list()
function file_path($file)
{
    return !is_dir($file) ? realpath($file) : null;
}
Ejemplo n.º 5
0
 }?>
 <div class="span11">
    <? 
    $i=0;
    foreach ($fileList as $file) {
      $meta=$s3->get_object_metadata($bucket, $file);
     
          if($i%5==0){   
          ?>
     <div class="span12">
         <ul class="thumbnails">
             <?}?>
             <li>
                 <div class="thumbnail">
                     <? 
                     $url=$s3->get_object_url($bucket, $file,'15 minutes');
                     if (isset($_SESSION['auth'])){
                         
                         ?>
                     <a href="<?echo $url;?>" target="_blank" title="" >
                     <img src="http://docs.google.com/viewer?url=<?echo $url;?>&a=bi&pagenumber=1&w=180&h=250" alt="" /> 
                     </a>
                     <?}
                     else{
                     ?>
                     <a rel="popover" href="#" title="" data-title="<? echo $meta['Headers']['x-amz-meta-title'];?>" data-content='<p>Sign in to view/download the book</p>' data-placement="right" data-trigger="hover" class="example"> 
                     <img src="http://docs.google.com/viewer?url=<?echo $url;?>&a=bi&pagenumber=1&w=180&h=250" alt="" /> 
                     </a>
                     <?}?>
                 </div>
                 <div class="bTitle"><? echo $meta['Headers']['x-amz-meta-title'];?></div>
Ejemplo n.º 6
0
 /**
  * Returns the URL for an object saved on Amazon S3.
  *
  * @param string $path
  *
  * @return string
  */
 protected function getObjectUrl($path)
 {
     return $this->storage->get_object_url($this->bucket, $path, 0, $this->objUrlOptions);
 }
Ejemplo n.º 7
0
if (isset($_GET['load'])) {
    $dbData = $db->Raw("SELECT `user`,`link`,`type`,`server` FROM `userdb_uploads` WHERE `xid`='{$xid}'");
    $type = $dbData[0]['type'];
    $server = $dbData[0]['server'];
    if ($type == 'upload' && $server != 's3') {
        $linkSplit = split("/", $dbData[0]['link']);
        $drive = $linkSplit[4];
        $userFolder = $linkSplit[5];
        $fileName = $linkSplit[6];
        $t_hex = sprintf("%08x", time());
    }
    $db->logActivity($dbData[0]['user'], 'logStart', $xid);
    $link = $dbData[0]['link'];
    if ($server == 's3') {
        $s3 = new AmazonS3();
        $link = $s3->get_object_url('fb-music', $link, '10 seconds');
    }
    $link = urlencode($link);
    if ($type == 'upload' && $server != 's3') {
        $link_type = 1;
        echo "linkType=" . $link_type . "&t_hex=" . $t_hex . "&drive=" . $drive . "&userFolder=" . $userFolder . "&filename=" . $fileName . "";
    } else {
        $link_type = 2;
        echo "linkType=" . $link_type . "&link=" . $link . "";
    }
} else {
    if (isset($_GET['logFullPlay'])) {
        $dbData = $db->Raw("SELECT `user` FROM `userdb_uploads` WHERE `xid`='{$xid}'");
        $db->logActivity($dbData[0]['user'], 'logFullPlay', $xid);
    }
}