Skip to content

Instantly share code, notes, and snippets.

@PizzaLiu
Created May 30, 2013 04:50
Show Gist options
  • Save PizzaLiu/5675784 to your computer and use it in GitHub Desktop.
Save PizzaLiu/5675784 to your computer and use it in GitHub Desktop.
// <form method="post" autocomplete="off" action="#" enctype="multipart/form-data">
// <input name="pic" id="pic" type="file" />
// </form>
// 文件数组格式 'pic' 为input name属性
$_FILES['pic'] =
array(
[name] => Balloon.bmp
[type] => image/bmp
[tmp_name] => C:\Windows\Temp\phpF4CC.tmp
[error] => 0
[size] => 18037
);
// 获取文件后缀
$temp_arr = explode('/', $_FILES['pic']['type']);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
// 转存文件
$file_uploaded_path = $upload_path.mktime().rand(100,999).'.'.$file_ext;
move_uploaded_file($file_element['tmp_name'],$file_uploaded_path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment