PHP Uploading Multiple Files to Amazon S3 Server

PHP Uploading Multiple Files to Amazon S3 Server

PHP Uploading Multiple Files to Amazon S3 Server

In this Post We Will Explain About is PHP Uploading Multiple Files to Amazon S3 Server With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Upload Files to Amazon S3 using PHPExample

In this post we will show you Best way to implement Uploading multiple files to Amazon S3 from PHP, hear for Amazon S3 File Upload Using PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

here :Upload file on amazon S3 with PHP SDK Download – Simple Login to Amazon website and account and click here to get You App’s Access Credentials.

Uploading multiple files to Amazon S3 from PHP

s3_config.php

 <?php
//Your Bucket Name
$bucket_name="YOUR_BucketName"; // Like as a media
if (!class_exists('S3'))require_once('S3.php');

//Your Cridentials AWS access info to Upload Files to Amazon S3 using PHP
if (!defined('awsAccessKey')) define('awsAccessKey', 'YOUR_ACCESS_KEY');  //Like as AKWEDFHRH7P354WBAI2Q 
if (!defined('awsSecretKey')) define('awsSecretKey', 'YOUR_ACCESS_Secret_KEY'); // Like as a LDQDd3+5NC1cBkdq5Tm2TZyzYAGv5utZBj+dghye

$s3 = new S3(awsAccessKey, awsSecretKey);
$s3->putBucket($bucket_name, S3::ACL_PUBLIC_READ);
?>

index.php

Upload Files to Amazon S3 using PHP To The file data contains PHP source code and HTML code to upload or submit form.

<?php
include('image_check.php'); 
$response_message='';
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$name = $_FILES['file']['name'];
	$size = $_FILES['file']['size'];
	$tmp = $_FILES['file']['tmp_name'];
	$ext = checkExtension($name);

	if(strlen($name) > 0)
	{
	if(in_array($ext,$check_valid_formats))
	{
	
		if($size<(1024*1024))
		{
			include('s3_config.php');
			$real_pic_name = time().".".$ext;

			if($s3->putObjectFile($tmp, $bucket_name , $real_pic_name, S3::ACL_PUBLIC_READ) )
			{
				$response_message = "S3 Upload Successful.";
				$uploads3filename='http://'.$bucket_name.'.s3.amazonaws.com/'.$real_pic_name;
				echo "<img src='$uploads3filename'/>";
				echo 'S3 File URL:'.$uploads3filename;
			}
			else
			$response_message = "your S3 Upload Fail.";

		}
		else
		$response_message = "Image size Maximum 1 MB";

	}
	else
	$response_message = "Invalid Your file, please upload any image file.";

	}
	else
	$response_message = "Please select any image file.";

}
?>
<form action="" method='post' enctype="multipart/form-data">
Upload image file here
<input type='file' name='file'/> 
<input type='submit' value='Upload Image'/>
<?php echo $response_message; ?>
</form>

image_check.php

 <?php
function checkExtension($str)
{
	$i = strrpos($str,".");
	if (!$i) { return ""; }
	$l = strlen($str) - $i;
	$ext = substr($str,$i+1,$l);
	return $ext;
}
//Here we can simple add valid new file extensions. 
	$check_valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP");
?>

Example

I hope you have Got What is Multiple Images Upload to Amazon S3 using PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Jquery simple rating system with star
  2.   Laravel Get HTTP hostname with Example
  3.   jQuery black gradient background effect Hover Slider With CSS
  4.   Count total number of items in nested array in PHP
  5.   Laravel Combine two DB query results Example
  6.   VueJS Accessing index using v-for loop
  7.   Vue JS Axios Post Request using Laravel Example
  8.   For Loop inside React JSX components
  9.   Codeigniter delete query from Database
  10.   How to Merge Two Eloquent Collections in Laravel?