Saver.php

Saver.php

Summary

Saver.php is a convenience class for PHP developers to save or move files to the local filesystem or Amazon S3 (other options coming soon such as Dropbox, Google Drive, and HugeGlobal as well as copying/moving files between external sources(AWS->HugeGlobal for instance)).

Dependencies

Amazon AWS PHP Client Library (v2): http://docs.aws.amazon.com/aws-sdk-php/v2/guide/installation.html

Amazon AWS PHP Client Library (v3): Soon to be supported

Config File

<?php
	define("aws_key", "PLQ182QI4G6EUYUCKTQA");
	define("aws_secret", "e4NFh5QrRfBHep934FEW6C9A7hR0RFrlqiAIx3AT");
	define("aws_region", "us-west-1");
	
	//Local File System Storage
	define("uploadDir", "/media/encrypted/UploadFolderTest");

	//S3
	define("aws_s3Bucket", "myBucket123");

?>

Usage

<?php
	include dirname(__FILE__) . "/s3Creds.php";
	include dirname(__FILE__) . "/awsPHP/aws-autoloader.php";
	use Aws\S3\S3Client;
	use Aws\Exception\AwsException;
	include dirname(__FILE__) . "/Saver.php";
	
	$s = new Saver();
	$s->save(array(
		"content"=>"The content for the file",
		"fileName"=>"greatFile.txt"
	));
	//Save to uploads folder
	$s->save(array(
		"content"=>"The content for the file",
		"fileName"=>"greatFile.txt",
		"uploadDir"=>uploadDir
	));
	
	//Ex 2: Save a file to the local filesystem (Copy)
	$s->save(array(
		"sourceFile"=>"greatFile.txt",
		"fileName"=>"greatFileCopy.txt"
	));
	//Save a copy to uploads folder
	$s->save(array(
		"content"=>"The content for the file",
		"fileName"=>"greatFile.txt",
		"uploadDir"=>uploadDir
	));
	
	//Ex 3: Save a file to the local filesystem (Move)
	$s->move(array(
		"sourceFile"=>"greatFileCopy.txt",
		"fileName"=>"greatFileMoved.txt"
	));
	
	//Move to uploads folder, perfect for handling file uploads
	$s->save(array(
		"sourceFile"=>"greatFileCopy.txt",
		"fileName"=>"greatFileMoved.txt",
		"uploadDir"=>uploadDir
	));
	
	
	//S3
	$s3Saver = new Saver(array(
		"destination"=>"s3",
		"aws_region"=>aws_region,
		"aws_bucket"=>aws_s3Bucket,
		"aws_bucketARN"=>aws_s3BucketARN,
		"aws_key"=>aws_key,
		"aws_secret"=>aws_secret
	));
	
	//Save content to an S3 file (Copy)
	$s3Saver->save(array(
		"content"=>"The content for the file",
		"fileName"=>"myS3File.txt"
	));
	
	//Save content to an S3 file (Copy)
	$s3Saver->save(array(
		"sourceFile"=>"greatFile.txt",
		"fileName"=>"greatFileCopy.txt"
	));
	
	//Ex 1: Save content to an S3 file (Move)
	$s3Saver->move(array(
		"sourceFile"=>"greatFile.php",
		"fileName"=>"myGreatFile.php"
	));
?>

Download for More Fun:

file_downloadSaver.php


Explore Chakra7 Today