Example #1
0
 /**
  * @covers mychaelstyle\utils\File::base64encode
  * @covers mychaelstyle\utils\File::base64decode
  * @covers mychaelstyle\utils\File::base64
  */
 public function testEncode()
 {
     $expected = $this->example_text;
     $path = $this->org_example;
     $to = tempnam(DIR_TEST . '/tmp', 'encoded_');
     $recover = tempnam(DIR_TEST . '/tmp', 'encoded_');
     \mychaelstyle\utils\File::base64encode($path, $to);
     \mychaelstyle\utils\File::base64decode($to, $recover);
     $this->assertEquals($expected, file_get_contents($recover));
     unlink($to);
     unlink($recover);
 }
Example #2
0
 /**
  * put file
  * @param string $srcPath
  * @param string $dstUri
  * @param array $options
  */
 public function put($srcPath, $dstUri, $options = array())
 {
     $dstUri = $this->__formatUri($dstUri);
     $pdo = $this->connections[0];
     $this->remove($dstUri);
     $tmp = tempnam(sys_get_temp_dir(), 'tmp_mychaelstyle_storage_mysql_');
     \mychaelstyle\utils\File::base64encode($srcPath, $tmp);
     $contents = file_get_contents($tmp);
     try {
         $sql = sprintf('INSERT INTO %s (%s,%s)VALUES(:uri,:contents)', $this->table, $this->field_uri, $this->field_contents);
         $statement = $pdo->prepare($sql);
         $statement->bindValue(':uri', $dstUri, \PDO::PARAM_STR);
         $statement->bindValue(':contents', $contents, \PDO::PARAM_STR);
         $statement->execute();
         @unlink($tmp);
     } catch (\Exception $e) {
         @unlink($tmp);
         throw new \mychaelstyle\Exception('File provider mysql: fail to select file!', 0, $e);
     }
 }