现在已经通过http上传成功了,临时 文件夹是uploads,现在怎么样加入到数据库里呢,然后再通过固定的字段获取到用户界面呢(可以主要指导一下图片和MP3吗)
<?php
header('content-type:text/html;charset=utf-8');
$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;
if (move_uploaded_file($fileInfo['tmp_name'],$destination)) {
echo '文件上传成功';
}else{
echo '文件上传失败 ';
}
}else{
switch ($error) {
case 1:
echo "上传文件超过了php配置文件中upload_max_filesize选项的值";
break;
case 2:
echo "超过了表单MAX_FILE_SIZE限制的大小";
break;
case 3:
echo "文件部分被上传";
break;
case 4:
echo "没有选择上传文件";
break;
case 6:
echo "没有找到临时目录";
break;
case 7:
case 8:
echo "系统错误";
break;
}
}
?>
书生