Example #1
0
 function testGetCumulativeFilenameShouldContainOnlyPlainCharacters()
 {
     foreach ($this->_bogusFilenames as $origFilename) {
         $newFilename = Garp_File::getCumulativeFilename($origFilename);
         $this->assertTrue($this->_containsOnlyPlainCharacters($newFilename), "Original filename: [{$origFilename}], new filename: [{$newFilename}]");
     }
 }
Example #2
0
 /**
  * @param String $filename
  * @param String $data Binary file data
  * @param Boolean $overwrite Whether to overwrite this file, or create a unique name
  * @param Boolean $formatFilename Whether to correct the filename,
  *                                f.i. ensuring lowercase characters.
  * @return String Destination filename.
  */
 public function store($filename, $data, $overwrite = false, $formatFilename = true)
 {
     $this->_verifyDirectory($filename);
     if ($formatFilename) {
         $filename = Garp_File::formatFilename($filename);
     }
     if (!$overwrite) {
         while ($this->exists($filename)) {
             $filename = Garp_File::getCumulativeFilename($filename);
         }
     }
     if ($this->_gzip) {
         $data = gzencode($data);
     }
     if (file_put_contents($this->_getFilePath($filename), $data) !== false) {
         chmod($this->_getFilePath($filename), self::PERMISSIONS);
         return $filename;
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * @param string $filename
  * @param string $data               Binary file data
  * @param boolean $overwrite         Whether to overwrite this file, or create a unique name
  * @param boolean $formatFilename    Whether to correct the filename,
  *                                   f.i. ensuring lowercase characters.
  * @return string                    Destination filename.
  */
 public function store($filename, $data, $overwrite = false, $formatFilename = true)
 {
     $this->_initApi();
     $this->_createBucketIfNecessary();
     if ($formatFilename) {
         $filename = Garp_File::formatFilename($filename);
     }
     if (!$overwrite) {
         while ($this->exists($filename)) {
             $filename = Garp_File::getCumulativeFilename($filename);
         }
     }
     $path = $this->_config['bucket'] . $this->_getUri($filename);
     $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ);
     if (false !== strpos($filename, '.')) {
         $ext = substr($filename, strrpos($filename, '.') + 1);
         if (array_key_exists($ext, $this->_knownMimeTypes)) {
             $mime = $this->_knownMimeTypes[$ext];
         } else {
             $finfo = new finfo(FILEINFO_MIME);
             $mime = $finfo->buffer($data);
         }
     } else {
         $finfo = new finfo(FILEINFO_MIME);
         $mime = $finfo->buffer($data);
     }
     $meta[Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER] = $mime;
     if ($this->_config['gzip'] && $this->_gzipIsAllowedForFilename($filename)) {
         $meta['Content-Encoding'] = 'gzip';
         $data = gzencode($data);
     }
     if ($this->_api->putObject($path, $data, $meta)) {
         return $filename;
     }
     return false;
 }