<?php
header('content-type:text/html;charset=utf-8');
require_once('conn.php');
$fileInfo=$_FILES['myFile'];
$filename=$fileInfo['name'];
$type=$fileInfo['type'];
$tmp_name=$fileInfo['tmp_name'];
$size=$fileInfo['size'];
$error=$fileInfo['error'];
$maxSize=99999999;
$allowExt=array('jpg','jpeg','mp3');
if ($error==UPLOAD_ERR_OK) {
if ($fileInfo['size']>$maxSize) {
exit('文件过大');
}
$ext=pathinfo($fileInfo['name'],PATHINFO_EXTENSION);
if(!in_array($ext, $allowExt)){
exit('非法文件类型');
}
if (!is_uploaded_file($fileInfo['tmp_name'])) {
exit('文件不是通过HTTP POST方式上传来的');
}
$path='uploads';
//防止重名覆盖
$uniName=md5(uniqid(microtime(true),true)).'.'.$ext;
//echo $uniName;exit;
$destination=$path.'/'.$uniName;
//$destination=$path.'/'.date("YmdHis").$fileInfo['name'];
if (move_uploaded_file($fileInfo['tmp_name'],$destination)) {
echo '文件上传成功';
}else{
echo '文件上传失败 ';
}
}
?>
<?php
require_once('conn.php');
if (!empty($_POST['submit'])){
$SgName=$_POST["singername"];
$Sex=$_POST["sex"];
$SgCon=$_POST["content"];
$Cou=$_POST["cou"];
$sql="select into singer(SgName,SgImg,Sex,SgCon,Cou) values ('$SgName','$destination','$Sex','$SgCon','$Cou')";
mysql_query($sql);
$num = mysql_affected_rows();
if ($num>0) {
echo "<script>alert('添加成功');location='gls.php';</script>";
}else{
echo "<script>alert('添加失败');location='gls.php';</script>";
}
}
?>
skyeorz
爱学习的搬砖工人