[HTML5]inputで複数ファイルのアップロード

inputで複数ファイルのアップロード。
IE9は未対応 omg!
Sample

index.html

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>html5によるファイル複数アップロード</title>
<meta name="description" content="****">
<meta name="keywords" content="****">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no,address=no,email=no">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
    画像複数選択<input type="file" name="image_file[]" multiple="multiple" accept="image/*"/>
    <input type="submit"/>
</form>
</body>
</html>

upload.php

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>html5によるファイル複数アップロード</title>
<meta name="description" content="****">
<meta name="keywords" content="****">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="format-detection" content="telephone=no,address=no,email=no">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
if(isset($_FILES["image_file"])){
	$i=0;
	$data=getReformFilesData();
	foreach ($data as $v) {
		$ext=end(explode('.', $v["name"]));
		$filename='./test'.($i++).$ext;
		$result = @move_uploaded_file( $v["tmp_name"], $filename);
		if($result){
			echo '<img src="'.$filename.'" width="300"/><br/>';
		}else{
			echo 'エラー<br/>';
		}
		foreach($v as $key => $v2){
			echo $key.' : '.$v2.'<br/>';
		}
		echo '<hr><br/>';
	}	
}
function getReformFilesData(){
	if(isset($_FILES["image_file"])){
		$t=array();
		$i=0;
		foreach ($_FILES["image_file"] as $key=>$list) {
			foreach ($list as $no => $v) {
				$t[$no][$key]=$v;
			}
		}
		return $t;
	}else{
		return array();
	}
}
?>

</body>
</html>

[iOS6]Safariでinput type=”file” #2

iOS6のSafariからformのinput type=”file”に対応しているので試しました。#2
Safariでinput type=”file” #1と違うところは写真だけ選ばせる点
Sample

sc00
formを作ると左のように表示される。

sc01
写真[ファイルを選択]をタップしたところ

sc02
写真を選択したところ

sc03
動画[ファイルを選択]をタップしたところ

sc04
動画を選択したところ

sc05
[送信]をタップして遷移したところ

index.html

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>sample00</title>
<meta name="description" content="****">
<meta name="keywords" content="****">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no,address=no,email=no">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
	<label>写真</label><input type="file" name="selectedPhoto" accept="image/*">
	<br/>
	<br/>
	<label>動画</label><input type="file" name="selectedMovie" accept="video/*">
	<br/>
	<br/>
	<input type="submit"/>
</form>
</body>
</html>

upload.php

<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>sample00</title>
<meta name="description" content="****">
<meta name="keywords" content="****">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="format-detection" content="telephone=no,address=no,email=no">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<?php
if(isset($_FILES["selectedPhoto"])){
	if($_FILES["selectedPhoto"]["error"]==0) {
		$ext=end(explode('.', $_FILES["selectedPhoto"]["name"]));
		$filename='./test.'.$ext;
		$result = @move_uploaded_file( $_FILES["selectedPhoto"]["tmp_name"], $filename);
		if($result){
			echo '<img src="'.$filename.'" width="300"/><br/>';
		}else{
			echo 'エラー<br/>';
		}
	}elseif ($_FILES["selectedPhoto"]["error"]==1) {
		echo 'ファイルサイズが大きすぎます。';
	}
	foreach($_FILES["selectedPhoto"] as $key => $v){
		echo $key.' : '.$v.'<br/>';
	}
}
?>
<br/><hr><br/>
<?php
if(isset($_FILES["selectedMovie"])){
	if ($_FILES["selectedMovie"]["error"]==0) {
		$ext=end(explode('.', $_FILES["selectedMovie"]["name"]));
		$filename='./test.'.$ext;
		$result = @move_uploaded_file( $_FILES["selectedMovie"]["tmp_name"], $filename);
		if($result){
			echo '<video src="'.$filename.'"></video> ';
		}else{
			echo 'エラー<br/>';
		}
	}elseif ($_FILES["selectedMovie"]["error"]==1) {
		echo 'ファイルサイズが大きすぎます。';
	}
	foreach($_FILES["selectedMovie"] as $key => $v){
		echo $key.' : '.$v.'<br/>';
	}
}
?>
</body>
</html>

[CakePHP 2.x]form->radioのvalue値を指定する。

form->radioのvalue値を指定する。

<?= $this->Form->create('samples', array('type' => 'post', 'action' => 'sample1')); ?>
<ul class="info-list">
    <li>
        <label class="radio">
<?php
$options = array('value1'=>'ラベル1','value2'=>'ラベル2','value3'=>'ラベル3','value4'=>'ラベル4');
$attributes = array("legend" => false,
                    'label'=> false,
                    'separator'=>'</label></li><li class="radio"><label class="radio">',
                    'value'=>'value1'
                    );
echo $this->form->radio('radioGroup1', $options, $attributes);
?>
        </label>
    </li>
</ul>
<div class="textcenter margin-top1"><button type="submit" class="btn btn-wide3">submit</button></div>
<?= $this->form->end() ?>

サンプル

[PHP]preg_replaceで複数の文字列置換

preg_replaceで複数の文字列置換

<?php
$string='ABC DEF GHI JKL MNO ABC DEF GHI JKL';
$pattern=array("/ABC/","/DEF/","/MNO/");
$replace=array('あいう','えおか','ほげ');
$result=preg_replace($pattern, $replace, $string);
echo $result;
?>

結果

あいう えおか GHI JKL ほげ あいう えおか GHI JKL

サンプル

[objective-c]UIButtonをドラッグする

UIButtonをドラッグする

UIButton*btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn addTarget:self action:@selector(onTouchDragInside:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[self.view addSubview:btn];

-(void)onTouchDragInside:(UIButton*)btn withEvent:(UIEvent*)event{
    UITouch *touch=[[event touchesForView:btn] anyObject];
    CGPoint prevPos=[touch previousLocationInView:btn];
    CGPoint pos=[touch locationInView:btn];
    float dX=pos.x-prevPos.x;
    float dY=pos.y-prevPos.y;
    btn.center=CGPointMake(btn.center.x+dX,btn.center.y+dY);
}

[objective-c]ドロップシャドウを付ける

ドロップシャドウを付ける

#import <QuartzCore/QuartzCore.h>

UIImageView*iv=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"test.png"]];
iv.layer.shadowOpacity=0.4;
iv.layer.shadowOffset=CGSizeMake(2.0, 2.0);
[self.view addSubview:iv];
//iv.clipsToBounds=YES; これがあるとドロップシャドウが出ない