Esempio n. 1
0
 /**
  * Save a file.
  *
  * @param $path
  * @param $content
  *
  * @return bool
  */
 public function saveFile($path, $content)
 {
     $path = $this->cleanFolder($path);
     if ($this->disk->exists($path)) {
         $this->errors[] = 'File ' . $path . ' already exists.';
         return false;
     }
     return $this->disk->put($path, $content);
 }
Esempio n. 2
0
 /**
  * Uploads a file
  *
  * @param string $file File contents
  * @param string $extension File extension
  * @param null|string $context File context
  * @param null|string $sizeName Size directory name
  * @param null|string $fileName Predefined filename
  *
  * @return string
  */
 public function uploadFile($file, $extension, $context = null, $sizeName = null, $fileName = null)
 {
     if (!$this->filesystemAdapter instanceof FilesystemAdapter) {
         throw new IcrRuntimeException('File manager has no file system adapter no set!');
     }
     $path = $this->path($context, $sizeName);
     if (null === $fileName) {
         $hash = $this->generate($this->filesystemAdapter, $extension, $path);
         $fileName = $hash . '.' . $extension;
     } else {
         $fileName = preg_replace('/\\.[A-z]{3,4}$/', '', $fileName);
         $fileName = $fileName . '.' . $extension;
     }
     $imageExists = $this->filesystemAdapter->exists($path . '/' . $fileName);
     if ($imageExists) {
         throw new \RuntimeException("Image {$fileName} already exists at path {$path}");
     }
     $path = $path . $fileName;
     $this->filesystemAdapter->put($path, $file);
     return $fileName;
 }
Esempio n. 3
0
 /**
  *@depends testCreateBucket
  */
 public function testPutFile($s3_client)
 {
     //start create laravel filesystem adapter
     $cloud_adapter = new AwsS3Adapter($s3_client, $this->bucket_name, $this->root_folder_in_bucket);
     $filesystem = new Filesystem($cloud_adapter);
     $laravel_filesystem_adapter = new FilesystemAdapter($filesystem);
     //end create laravel filesystem adapter
     //start pul file
     $laravel_filesystem_adapter->put($this->bucket_file_path, $this->bucket_file_content, FilesystemContract::VISIBILITY_PUBLIC);
     //end put file
     //start check file exists
     $this->assertTrue($laravel_filesystem_adapter->exists($this->bucket_file_path));
     //end check file exists
     //start check contect of file
     $this->assertEquals($this->bucket_file_content, $laravel_filesystem_adapter->get($this->bucket_file_path));
     //end check contect of file
     return $laravel_filesystem_adapter;
 }
Esempio n. 4
0
 /**
  * Write the contents of a file.
  *
  * @param string $path
  * @param string|resource $contents
  * @param string $visibility
  * @return bool 
  * @static 
  */
 public static function put($path, $contents, $visibility = null)
 {
     return \Illuminate\Filesystem\FilesystemAdapter::put($path, $contents, $visibility);
 }
Esempio n. 5
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use Illuminate\Filesystem\FilesystemAdapter;
//start define settings
$end_point = 'http://webapp.dev:4569';
$bucket_region = 'us-east-1';
$bucket_name = 'default1bucket';
$root_folder_in_bucket = 'news';
$file_path = 'test.jpg';
//end define settings
//start create S3 client
$s3_client = new S3Client(['credentials' => ['key' => 'AKIAIOSFODNN7EXAMPLE', 'secret' => 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'], 'region' => $bucket_region, 'version' => 'latest', 'endpoint' => $end_point, 'scheme' => 'http']);
//end create S3 client
//start create bucket
$s3_client->createBucket(['ACL' => 'private', 'Bucket' => $bucket_name, 'CreateBucketConfiguration' => ['LocationConstraint' => $bucket_region]]);
//end create bucket
//start create laravel filesystem adapter
$cloud_adapter = new AwsS3Adapter($s3_client, $bucket_name, $root_folder_in_bucket);
$filesystem = new Filesystem($cloud_adapter);
$disk = new FilesystemAdapter($filesystem);
//end create laravel filesystem adapter
//start put file on disk
if (!$disk->exists($file_path)) {
    $disk->put($file_path, file_get_contents('../resources/assets/img/test.jpg'));
}
//start put file on disk
print "<img src='" . $disk->url($file_path) . "'/>";
 /**
  * @param File        $localFile
  * @param string      $remotePath
  * @param string|null $filename
  *
  * @return bool
  */
 private function copyToRemote(File $localFile, $remotePath, $filename = null)
 {
     $filename = $filename ? $filename : $localFile->getBasename();
     $success = $this->storage->put($remotePath . '/' . $filename, file_get_contents($localFile->getPathname()));
     return $success;
 }