Pass data of URL argument in PHP

Extract arguments by specify URL. In the $_GET array, the value specified by the URL is substituted. In the first argument, argument names in the URL are enclosed in single quotation marks.

if(isset($_GET['preview_date'])){
	$date = $_GET['preview_date'];
	echo $date . "<br>";
}
if(isset($_GET['preview_time'])){
	$time = $_GET['preview_time'];
	echo $time;
}

AWS Code deploy

Code Deploy Merit
– Automatic deployment
– Minimize Downtime
– Unified management
– Easy to introduce

umm, somehow I do not understand well.

What is code deploy
It is a service that allows you to simultaneously deploy programs to multiple instances tagged by CodeDeploy for programs created by users.

Features
– For multiple deployment objects, deployment speed can be adjusted one at a time, all at once, only half, etc.
– The deployment destination EC2 is automatically determined by an arbitrary tag
– Simply run aws-cli with the local deployment directory specified, zip it and push it to S3
– Just after post-deployment(permission change, Apache’s graceful etc) write in yml and put it in the directory to be deployed.

PHP Paging algorithm

Make variable number of items displayed on one page.
Prepare a number of array.

$coin = ["Bitcoin", "Ethereum", "Ripple", "Litecoin", "Ethereum Classic", "DASH", "Bitshares", "Monero", "NEM", "Zcash", "Bitcoin Cash", "Bitcoin Gold", "Monacoin", "Lisk", "Factom"];

$array_num = count($coin);
$page = 2;
$number = 4;

$i = 0;
foreach($coin as $value){
	if(($number * ($page - 1) - 1 < $i) && ($i < $number * $page)){
		echo $value . "<br>";
	}
	$i++;
}

-> Ethereum Classic
DASH
Bitshares
Monero

It’s ok to change the variables, page and page_number with button.
It was easier than I thought♪

php date_format function and for use

The date_format function formats date and time values in a specified format.

$date = date_create('2019-01-17');

echo date_format($date, 'y/m/d') . "<br>";
echo date_format($date, 'y/m/d h:i:s') . "<br>";
echo date_format($date, 'g:i A') . "<br>";
echo date_format($date, 'G:i a') . "<br>";

-> 19/01/17
19/01/17 12:00:00
12:00 AM
0:00 am

php function reference
http://php.net/manual/en/function.date.php
It was said “date — Format a local time/date”

In laravel, if you want to set yyyy/mm/dd and hh:mm to validation, the specification of the format is the following code.

$validator = Validator::make($request->all(),[
     'date' => 'date_format:Y/m/d',
     'time' => 'date_format:H:i',
    ]);

Sample of PHP substr and mb_substr

“substr” is a function that can acquire a part of a specified character string.

here comes sample.

$char = "come on baby America";
echo substr($char, 1);

-> ome on baby America

If 1 is specified, character strings for the number of characters specified from o can be acquired.

$char = "502 bad gateway";
echo substr($char, 2, 7);

-> 2 bad g
From start position 2 to 7 characters.

mb_substr is also a function to retrieve a part of the specified character string, but what is the difference with substr?
mb_string can specify the character code of the character string in addition to specifying the starting position and the number of characters.

$char = "仮想通貨でおススメの通貨はありますか?";
echo substr($char, 2, 7, "utf-8");

-> Warning: substr() expects at most 3 parameters, 4 given in Standard input code on line 5

$char = "仮想通貨でおススメの通貨はありますか?";
echo mb_substr($char, 2, 7, "utf-8");

->通貨でおススメ

When using non-English, it’s easy to use, isn’t it?

What can we do aws monitoring tool “cloud watch”?

What can we do for CloudWatch??

-> CloudWatch is “A fully managed operation monitoring service” provided by AWS, those that monitor various resources of AWS.

In detail and features.
– Can be used without setup
– It detects an abnormal condition and automatically restores it
– Alert notification and action can be set according to metrics.

It can be monitored EC2, EBS, S3, and so on. Cloudwatch have three services.
– CloudWatch : You can make dashboards by graphing multiple items such as CPU and memory.
– CloudWatch Logs:Corresponds to Amazon Linux, RedHat, Windows etc, and by acquiring various logs by putting an agent in the instance. In addtion to OS, application logs are also supported, and you can let alert notice by keyword.
– CloudWatch Events:It is a service that causes some action to be executed by triggering API event.

Other way to watch log is checking access_log, error_log, and monitor_log from Linux.

Laravel5.7 upload file with extension

uploaded a file with a controller, but looked no file extension.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Image;

class ImageIndexController extends Controller
{
    public function index(){
    	return view('imageindex');
    }

    public function store(Request $request){

    	$request->file('image')->move(public_path('item'));
    	return view('imageindex');
    }
}

How come to fix it?

specify the extension with guessExtension method.
ImageIndexController.php

public function store(Request $request){

        $filename = $request->file('image') . "." . $request->file('image')->guessExtension();
    	$request->file('image')->move(public_path('item'), $filename);
    	return view('imageindex');
    }

/image/index

I got it.

I want to display the uploaded image in view.
Before that, you want to make the file name arbitrary, such as date. It seems to be so easy.

$filename = date("YmdHis") . "." . $request->file('image')->guessExtension();

oh, OK.

Laravel5.7 mime type

Use mime type to specify the extension of the image in laravel.

A full listing of MIME types and their corresponding extensions may be found at the following location:
https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

I wonder if this match??

custom request
ImageRequest.php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ImageRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'image' => 'image|mimes:jpg,jpeg,gif,png',
        ];
    }
    public function messages()
    {
        return [
            'image.required' => '画像以外のファイルが指定されています。画像ファイル(png/jpg/jpeg/gif)を指定して下さい',
        ];
    }
}

Upload image with Laravel5.7

Upload images with Laravel5.7.
Configure routing to save images posted from view.

Route::get('/image/index', 'ImageIndexController@index');
Route::post('/image/index', 'ImageIndexController@store');

imageindex.blade.php

@extends('layouts.image')
@section('title', '画像管理')

@section('breadcrumb')
	@@parent
	<ul class="breadcrumb">
      <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb" >
        <a href="/top" itemprop="url">
          <span itemprop="title">ホーム</span>
        </a>
      </li>
      <li itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb" >
        <a href="/top" itemprop="url">
          <span itemprop="title">画像管理</span>
        </a>
      </li>
    </ul>
@endsection

@section('content')
<h2>画像管理</h2>
      <hr>
      <form action="/image/index" method="POST" enctype="multipart/form-data">
        <div id="drag-drop-area">
         <div class="drag-drop-inside">
          <p class="drag-drop-info">ここにファイルをアップロード</p>
          <p>または</p>
          <!-- <input type="file" value="ファイルを選択" name="image"> -->
          <p class="drag-drop-buttons"><input id="fileInput" type="file" value="ファイルを選択" name="image"></p>
              <!-- <input type="submit" value="送信"> -->
           </div>
          </div>
            

      <div class="button_wrapper remodal-bg">
         <button type="submit" value="送信" id="square_btn" onClick="location.href='#modal'">登録</button>
      </div>
       </form> 

      <!-- remodal -->
      <div class="remodal" data-remodal-id="modal">
        <button data-remodal-action="close" class="remodal-close"></button>
        <h1>保存しますか</h1>
        <p>
          入力した内容で宜しいでしょうか?
        </p>
        <br>
        <button data-remodal-action="cancel" class="remodal-cancel">Cancel</button>
        <button data-remodal-action="confirm" class="remodal-confirm">OK</button>
      </div>
      <!-- /remodal -->

      <script>
      var fileArea = document.getElementById('drag-drop-area');
      var fileInput = document.getElementById('fileInput');

      fileArea.addEventListener('dragover', function(evt){
        evt.preventDefault();
        fileArea.classList.add('dragover');
      });

      fileArea.addEventListener('dragleave', function(evt){
        evt.preventDefault();
        fileArea.classList.remove('dragover');
      });

      fileArea.addEventListener('drop', function(evt){
        evt.preventDefault();
        fileArea.classList.remove('dragenter');
        var files = evt.dataTransfer.files;
        fileInput.files = files;
      });

      </script>
      
@endsection

Upload an image from a form with php

Move the uploaded image with move_uploaded_file to the specified fold.
Then let the image be displayed again in the view.

if(file_exists($_FILES['upfile']['tmp_name'])){
	$ext = substr($_FILES['upfile']['name'], strrpos($_FILES['upfile']['name'],'.') + 1);
	echo $ext."<br>";
	if(strtolower($ext) !== 'png' && strtolower($ext) !== 'jpg' && strtolower($ext) !== 'jpeg' && strtolower($ext) !== 'gif'){
		echo '画像以外のファイルが指定されています。画像ファイル(png/jpg/jpeg/gif)を指定して下さい';
		exit();
	}
	$image = "img/".basename($_FILES['upfile']['tmp_name']).".".$ext;
	if(move_uploaded_file($_FILES['upfile']['tmp_name'], $image)){
		echo "アップロード成功!!";
	} else {
		echo "失敗";
	}
	// insert $image into mysql
}


?>
<div id="content">
<h2>画像管理</h2>
<hr>
<form action="#" method="POST" enctype="multipart/form-data">
<div id="drag-drop-area">
 <div class="drag-drop-inside">
  <p class="drag-drop-info">ここにファイルをアップロード</p>
  <p>または</p>
  <!-- <input type="file" value="ファイルを選択" name="image"> -->
  <p class="drag-drop-buttons"><input id="fileInput" type="file" value="ファイルを選択" name="upfile"></p>
      <input type="submit" value="送信">
   </div>
  </div>
  <img src="<?php echo $image; ?>">
</form>

Before

After

Will implement this in laravel.
Or, in the case of laravel, is there a form to upload images?