Created
November 14, 2014 14:26
-
-
Save stewones/a3a42efde6f9712a3772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function _upload_image() { | |
// This is a simplified example, which doesn't cover security of uploaded images. | |
// This example just demonstrate the logic behind the process. | |
// files storage folder | |
$dir = base_path('public/temp/'); | |
$_FILES['file']['type'] = strtolower($_FILES['file']['type']); | |
if ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/pjpeg') { | |
$extension = explode('/', $_FILES['file']['type']) [1]; | |
// setting file's mysterious name | |
$filename = md5(date('YmdHis')) . '.' . $extension; | |
$file = $dir . $filename; | |
// copying | |
if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) { | |
$s3 = AWS::get('s3'); | |
$store = $s3->putObject(array( | |
'Bucket' => 'esbox-email-images', | |
'Key' => $filename, | |
'SourceFile' => $file, | |
'ACL' => 'public-read', | |
)); | |
if (!empty($store['ObjectURL'])) { | |
//delete local file | |
if (file_exists($file)) unlink($file); | |
// displaying file | |
$array = array( | |
'filelink' => $store['ObjectURL'] | |
); | |
echo stripslashes(json_encode($array)); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment