Upload file on s3 AWS using PHP
- <?php
- include('checkimg.php'); // getExtension Method
- include('s3_config.php');
- $msg='';
- if($_SERVER['REQUEST_METHOD'] == "POST")
- {
- $name = $_FILES['file']['name'];
- $size = $_FILES['file']['size'];
- $tmp = $_FILES['file']['tmp_name'];
- $ext = getExtension($name);
- if(strlen($name) > 0)
- {
- // File format validation
- if(in_array($ext,$valid_formats))
- {
- // File size validation
- if($size<(1024*1024))
- {
- //Rename image name.
- $actual_image_name = time().".".$ext;
- if($s3->putObjectFile($tmp, $bucket , $actual_image_name, S3::ACL_PUBLIC_READ) )
- {
- $msg = "S3 Upload Successful.";
- $s3file='http://'.$bucket.'.s3.amazonaws.com/'.$actual_image_name;
- echo "<img src='$s3file'/>";
- echo 'S3 File URL:'.$s3file;
- }
- else
- $msg = "S3 Upload Fail.";
- }
- else
- $msg = "Image size Max 1 MB";
- }
- else
- $msg = "Invalid file, please upload image file.";
- }
- else
- $msg = "Please select 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 $msg; ?>
- </form>
Tags
AWS
AWS s3
AWS s3 file upload
file upload
file upload on s3
files
How to fetch file from S3
s3
s3 AWS
s3 file
s3 file upload
S3 file upload using PHP
S3 files
S3 get file
zip file on s3