php单图片上传。

时间:2022-06-26 14:28:05

1、input:file form 提交

/**
* 用户头像上传
* @param [type] $file 图像信息
*/
function domeadd($file){
if (is_array($_FILES['upload'])){
$path = '图片路径';
$name = date('d',time()).'_'.'img_'.uniqid();
$houzhui = substr($file['name'], strrpos($file['name'],'.'));
$newname = $name.$houzhui;
$year = date('Y',time());
$month = date('m',time());
$day = date('d',time());
$new_path=$path.'/'.$year.'/'.$month.'/'.$newname;
if (!file_exists($path.'/'.$year.'/'.$month)){
mkdir($path.'/'.$year.'/'.$month,0777,true);
}
move_uploaded_file($file['tmp_name'], $new_path);
return $new_path;
}
}