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>
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *