php代码public
function upload() {
$uplad_tmp_name = $_files['imgfile']['tmp_name'];
$uplad_name = $_files['imgfile']['name'];
$image_url = "";
//上传文件类型列表
$uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png');
//初始化变量
$date = date('ymdhis').uniqid();
//上传文件路径
$img_url = img_base_url.date('ym').
"/";
$img_url_data = "data/images/".date('ym').
"/";
if (!is_dir($img_url_data)) {
mkdir($img_url_data, 0777);
}
//如果当前图片不为空
if (!empty($uplad_name) && in_array($_files["imgfile"]["type"], $uptypes)) {
$uptype = explode(".", $uplad_name);
$newname = $date.
".".end($uptype);
$uplad_name = $newname;
//如果上传的文件没有在服务器上存在
if (!file_exists($img_url_data.$uplad_name)) {
//把图片文件从临时文件夹中转移到我们指定上传的目录中
$file = $img_url_data.$uplad_name;
move_uploaded_file($uplad_tmp_name, $file);
chmod($file, 0777);
/*
include(lib_path."/resize.class.php");
$resizeobj = new resize($file);
$resizeobj -> resizeimage(800, 9999999, 'auto');
$resizeobj -> saveimage($file, 100);
*/
$img_url1 = $img_url.$newname;
$this - > ajax_info(0, $img_url1, '上传成功');
}
}
}