Skip to content

Instantly share code, notes, and snippets.

@maimai-swap
Created February 4, 2014 01:11
Show Gist options
  • Save maimai-swap/8795722 to your computer and use it in GitHub Desktop.
Save maimai-swap/8795722 to your computer and use it in GitHub Desktop.
Laravel 4 で s3に htmlファイルを アップロードして、content-typeとcharsetもutf8で設定する。
<?php
// ControllerとかCommandとかのなかに適当に以下を書く
$image = Image::findOrFail($ad->image_id);
$content_type = explode(";",$image->spec)[0];
$spec_ext = explode("/", $content_type)[1];
$ad_array = $ad->toArray();
$display_text = "あああ表示文字";
$click_url = "http://example.com/test.html";
$pwd = getcwd();
$localpath_html = "$pwd/test.html";
$html_txt = '
<li>
<a href="'.$click_url.'">
<img src="http://'. $bucket. $image_key .'" width= "48" height= "48">
<p>'. str_replace("\r\b","<br/>",$display_text) .'</p>
</a>
</li>
';
file_put_contents($localpath_html, $html_txt);
$bucket = 'バケット名';
$s3 = AWS::get('s3');
$html_upload_path = "/test/test.html";
$s3 = AWS::get('s3');
$s3->putObject(array(
'Bucket' => $bucket,
'Key' => $html_upload_path,
'SourceFile' => $localpath_html,
'ContentType' => 'text/html; charset=utf-8',
));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment