[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; これがあるとドロップシャドウが出ない

[objective-c]UIImageの作り方

UIImageの作り方

NSString*fn=@"image.png";
UIImage*image1=[UIImage imageNamed:fn];
UIImage*image2=[UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] bundlePath],fn]];

NSURL*url=[NSURL URLWithString:@"http://yourdomain/image.png"];
NSData*data=[NSData dataWithContentsOfURL:url];
UIImage*image3=[UIImage imageWithData:data];

参考サイト
UIImage Class Reference
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html

[objective-c]animateWithDuration

beginAnimationsはiOS4以降非推奨なので、
より便利なanimateWithDurationを使いましょう。

[UIView animateWithDuration:0.3
    animations:^{
        //アニメーション内容
        targetView.frame=CGRectMake(0, 0, 100, 100);
    }
    completion:^(BOOL finished){
        //アニメーションが終わったとき
        [targetView removeFromSuperview];
        [targetView release];
        targetView=nil;
    }
];

参考サイト
UIView ClassMethods
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW110