Basic Upload With Page Hanging Until Upload Completes


<?php
include_once('config.php');
require 'awssdk/aws.phar';			//<SDK so we can access S3 storage

		global $AwsS3BucketName;
		global $AwsS3AccessKeyId;
		global $AwsS3AccessSecretKey;
		

		$sdk = new Aws\Sdk([
				'version' => 'latest',
				'region'  => 'eu-west-1',				//<<<<< REGION
				'credentials' => [
						'key'    => $AwsS3AccessKeyId,				//<<<<< S3 ACCESS KEY ID
						'secret' => $Aw

if (isset($_POST['submit']))
{
	//----- FORM SUBMITTED - UPLOAD FILE -----

	if (filesize($_FILES['file_uploaded1']['tmp_name']) > 0)
	{
		//Retrieve post variables
		$file = $_FILES['file_uploaded1'];
		$filename = $file['name'];				//This is the source filename
		$tmpname = $file['tmp_name'];			//This is where the file is temporarily stored

		$keyName = $filename;			//<<<This will be the filename

		//Upload the file
		try
		{
			$s3Client->putObject(
				array(
					'Bucket'=>$AwsS3BucketName,
					'Key' =>  $keyName,
					'SourceFile' => $tmpname,
					'StorageClass' => 'REDUCED_REDUNDANCY',		//<<<Optional parameter
					'ACL' => 'public-read'										//<<<Optional parameter
				)
			);
		}
		catch (S3Exception $e)
		{
			echo $e->getMessage();
		}
		catch (Exception $e)
		{
			echo $e->getMessage();
		}
	}
}
?>

<h1>Upload a file</h1>
<form action="" method="post" enctype="multipart/form-data" name="form" id="form">
        <label>Send this file</label>
        <input name="file_uploaded1" type="file" />
        <input name="submit" type="submit" value="Upload">
</form>
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.