Skip to content

Instantly share code, notes, and snippets.

@BastinRobin
Forked from JasonMortonNZ/gist:5499511
Last active August 29, 2015 14:13
Show Gist options
  • Save BastinRobin/3dbeff5005551adc1e49 to your computer and use it in GitHub Desktop.
Save BastinRobin/3dbeff5005551adc1e49 to your computer and use it in GitHub Desktop.
// Routes.php
Route::get('upload', function()
{
return View::make('upload-form');
});
Route::post('upload', function()
{
// Get and move uploaded file.
Input::file('image')->move("/tmp", "test-image.jpg");
// Register AWS instance
$s3 = App::make('aws')->get('s3');
$s3->putObject(array(
'Bucket' => 's3.trial',
'Key' => 'test-image',
'SourceFile' => '/tmp/test-image.jpg'
));
// Delete local file
File::delete("/tmp/test-image.jpg");
return 'Image uploaded to S3' . " - " . '<a href="/view-image">Click here to view image</a>';
});
Route::get('view-image', function()
{
$img = "test-image"; // Would be something like $user->img_url;
$url = "https://s3-us-west-2.amazonaws.com/s3.trial/" . $img; // Where s3.trial is your bucket name
return '<img src="' . $url . '">';
});
--------------------------
upload-form.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>S3 - Upload Form</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<dov class="row-fluid">
<span12>
<form action="upload" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Upload Image form</legend>
<label for="inputImage">Image:</label>
<input type="file" name="image" id="inputImage">
<input type="submit" value="upload" class="btn">
</fieldset>
</form>
</span12>
</dov>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment