軽く覚書的なもの。
Larave4を使って少しやった。
views/test.php
<!doctype html>
<html lang="ja-JP">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?= Form::open(array('url' => '' ,'files' => true)) ?>
<input name="image" type="file" />
<input type="submit">
<?= Form::close() ?>
</body>
</html>
controller/HomeController.php
<?php
public function showTest()
{
return View::make('test');
}
public function execTest()
{
$set_path = public_path('images/');
// ディレクトリは存在するか確認
if(!File::exists($set_path))
{
File::makeDirectory($set_path);
}
// ファイルは入力されたか
if(!Input::hasFile('image'))
{
return;
}
$file = Input::file("image");
// 情報を取得
$file_path = $file->getRealPath();
$name = $file->getClientOriginalName();
// ファイルをtmpから移動
File::move($file_path, $set_path . $name);
// 以降は。。。。
exit();
}