安装好环境后,将源码放入环境的相应项目目录:如wamp默认在在www下,xampp是在htdoc;
如果是完整的CMS源码,一般都只要访问localhost就会有自动安装引导,绑定数据库;按提示操作就行,如果不是,那么久要先绑定数据库(nosql类型数据库除外)选择目录中conf或者config,或者db,或者config.php等类似文件或者目录配置你的数据库或者缓存库就可以测试了(如果每有编程基础,建议先语言入门);操作简单但还真得专人来
边访问,边看错,报错改错,知道没错,祝你早日入门
可以参考:
一般是单独导入的,
在mysql上,要用mysql_import工具 把文本导入
sqlserver上可以用数据库备份工具恢复导入, 也可以使用其他数据库引擎通过ado到.
不需要源码,但是需要了解php源码所需要的库表结构.一般php源码里好多都有建立空库结构的源码.
FTP软件,,,然后上传数据库,在修改数据库配置参数就行了.
至于传到哪个文件夹内,根据空间商提供的不同名字的文件夹,这个不好确定,问问你的主机商吧.
直接传文件不用解压.
php
//文件和图片上传类
class UploadFile
{//类定义开始
public $maxSize = -1; // 上传文件的最大值
public $supportMulti = true; // 是否支持多文件上传
public $allowExts = array();// 允许上传的文件后缀// 留空不作后缀检 查
public $allowTypes = array(); // 允许上传的文件类型 // 留空不做检查
public $thumb = false; // 使用对上传图片进行缩略图处理
public $thumbMaxWidth; // 缩略图最大宽度
public $thumbMaxHeight; // 缩略图最大高度
public $thumbPrefix = 'thumb_'; // 缩略图前缀
public $thumbSuffix = '';
public $thumbPath = ''; // 缩略图保存路径
public $thumbFile='';// 缩略图文件名
public $thumbRemoveOrigin =false;// 是否移除原图
public $zipImages = false; // 压缩图片文件上传
public $autoSub = false; // 启用子目录保存文件
public $subType = 'hash';// 子目录创建方式 可以使用hash date
public $dateFormat = 'Ymd';
public $hashLevel = 1; // hash的目录层次
public $savePath = ''; // 上传文件保存路径
public $autoCheck = true; // 是否自动检查附件
public $uploadReplace = false;// 存在同名是否覆盖
// 例如可以是 time uniqid com_create_guid 等
// 必须是一个无需任何参数的函数名 可以使用自定义函数
public $saveRule = '';// 上传文件命名规则
private $error = '';// 错误信息
private $uploadFileInfo ;// 上传成功的文件信息
/**
+----------------------------------------------------------
* 架构函数
* @access public
*/
public function __construct($maxSize='',$allowExts='',$allowTypes='',$savePath='',$saveRule='')
{
if(!empty($maxSize) is_numeric($maxSize)) {
$this-maxSize = $maxSize;
}
if(!empty($allowExts)) {
if(is_array($allowExts)) {
$this-allowExts = array_map('strtolower',$allowExts);
}else {
$this-allowExts = explode(',',strtolower($allowExts));
if(!empty($allowTypes)) {
if(is_array($allowTypes)) {
$this-allowTypes = array_map('strtolower',$allowTypes);
$this-allowTypes = explode(',',strtolower($allowTypes));
if(!empty($savePath)) {
$this-savePath = $savePath;
if(!empty($saveRule)) {
$this-saveRule = $saveRule;
private function save($file)
$filename = $file['savepath'].$file['savename'];
if(!$this-uploadReplace is_file($filename)) {// 不覆盖同名文件
$this-error='文件已经存在!'.$filename;
return $this - error;
// 如果是图像文件 检测文件格式
if( in_array(strtolower($file['extension']),array('gif','jpg','jpeg','bmp','png','swf')) $this - error === getimagesize($file['tmp_name'])) {
$this-error = '非法图像文件';
$this-error = '文件上传保存错误!';
if($this-thumb in_array(strtolower($file['extension']),array('gif','jpg','jpeg','bmp','png'))) {
$image = getimagesize($filename);
if($this - error !== $image) {
//是图像文件生成缩略图
$thumbWidth=explode(',',$this-thumbMaxWidth);
$thumbHeight=explode(',',$this-thumbMaxHeight);
$thumbPrefix=explode(',',$this-thumbPrefix);
$thumbSuffix = explode(',',$this-thumbSuffix);
$thumbFile=explode(',',$this-thumbFile);
$thumbPath =
$this-thumbPath?$this-thumbPath:$file['savepath'];
// 生成图像缩略图
if(file_exists(dirname(__FILE__).'/Image.class.php'))
require_once(dirname(__FILE__).'/Image.class.php');
$realFilename = $this-autoSub?basename($file['savename']):$file['savename'];
for($i=0,$len=count($thumbWidth); $i$len; $i++) {
$thumbname=$thumbPath.$thumbPrefix[$i].substr($realFilename,0,strrpos($realFilename, '.')).$thumbSuffix[$i].'.'.$file['extension'];
Image::thumb($filename,$thumbname,'',$thumbWidth[$i],$thumbHeight[$i],true);
if($this-thumbRemoveOrigin) {
// 生成缩略图之后删除原图
unlink($filename);
return true;
* 上传文件
* @param string $savePath 上传文件保存路径
* @return string
* @throws ThinkExecption
public function upload($savePath ='') {
if(empty($savePath)) //如果不指定保存文件名,则由系统默认
$savePath = $this-savePath;
$savePath .= date('Ym',time())."/";
if(!is_dir($savePath)) { // 检查上传目录
}else{
if(!mkdir($savePath)){ // 尝试创建目录
$this-error = '上传目录'.$savePath.'不存在';return $this - error;
if(!is_writeable($savePath)) {
$this-error = '上传目录'.$savePath.'不可写'; return $this - error;
$fileInfo = array();
$isUpload = $this - error;
// 获取上传的文件信息
// 对$_FILES数组信息处理
$files = $this-dealFiles($_FILES);
foreach($files as $key = $file) {
//过滤无效的上传
if(!empty($file['name'])) {
//登记上传文件的扩展信息
$file['key'] = $key;
$file['extension'] = $this-getExt($file['name']);
$file['savepath'] = $savePath;
$file['savename'] = $this-getSaveName($file);
// 自动检查附件
if($this-autoCheck) {
if(!$this-check($file))
//保存上传文件
//echo "pre";print_r( $file );
if(!$this-save($file)) return $this - error;
/*
if(function_exists($this-hashType)) {
$fun = $this-hashType;
//上传成功后保存文件信息,供其他地方调用
unset($file['tmp_name'],$file['error']);
$fileInfo[] = $file;
$isUpload = true;
if($isUpload) {
$this-uploadFileInfo = $fileInfo;
return $fileInfo;
$this-error = '没有选择上传文件';
* 转换上传文件数组变量为正确的方式
* @access private
* @param array $files 上传的文件变量
* @return array
private function dealFiles($files) {
$fileArray = array();
foreach ($files as $file){
if(is_array($file['name'])) {
$keys = array_keys($file);
$count = count($file['name']);
for ($i=0; $i$count; $i++) {
foreach ($keys as $key)
$fileArray[$i][$key] = $file[$key][$i];
$fileArray=$files;
break;
return $fileArray;
* 获取错误代码信息
* @param string $errorNo 错误号码
* @return void
protected function error($errorNo)
switch($errorNo) {
case 1:
$this-error = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值';
$this-error = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
$this-error = '文件只有部分被上传';
$this-error = '没有文件被上传';
$this-error = '找不到临时文件夹';
$this-error = '文件写入失败';
default:
$this-error = '未知上传错误!';
return ;
* 根据上传文件命名规则取得保存文件名
* @param string $filename 数据
private function getSaveName($filename)
$rule = $this-saveRule;
if(empty($rule)) {//没有定义命名规则,则保持文件名不变
$saveName = $filename['name'];
if(function_exists($rule)) {
//使用函数生成一个唯一文件标识号
//使用给定的文件名作为标识号
if($this-autoSub) {
// 使用子目录保存文件
$saveName = $this-getSubName($filename).'/'.$saveName;
return $saveName;
* 获取子目录的名称
* @param array $file 上传的文件信息
private function getSubName($file)
switch($this-subType) {
case 'date':
$dir = date($this-dateFormat,time());
case 'hash':
$dir = '';
for($i=0;$i$this-hashLevel;$i++) {
$dir .= $name{0}.'/';
if(!is_dir($file['savepath'].$dir)) {
mkdir($file['savepath'].$dir);
return $dir;
* 检查上传的文件
* @param array $file 文件信息
* @return boolean
private function check($file) {
if($file['error']!== 0) {
//文件上传失败
//捕获错误代码
$this-error($file['error']);
//检查文件Mime类型
if(!$this-checkType($file['type'])) {
$this-error = '上传文件MIME类型不允许!';
//检查文件类型
if(!$this-checkExt($file['extension'])) {
$this-error ='上传文件类型不允许';
//文件上传成功,进行自定义规则检查
//检查文件大小
if(!$this-checkSize($file['size'])) {
$this-error = '上传文件大小超出限制!';
//检查是否合法上传
if(!$this-checkUpload($file['tmp_name'])) {
$this-error = '非法上传文件!';
* 检查上传的文件类型是否合法
* @param string $type 数据
private function checkType($type)
if(!empty($this-allowTypes))
return in_array(strtolower($type),$this-allowTypes);
* 检查上传的文件后缀是否合法
* @param string $ext 后缀名
private function checkExt($ext)
if(!empty($this-allowExts))
return in_array(strtolower($ext),$this-allowExts,true);
* 检查文件大小是否合法
* @param integer $size 数据
private function checkSize($size)
return !($size $this-maxSize) || (-1 == $this-maxSize);
* 检查文件是否非法提交
* @param string $filename 文件名
private function checkUpload($filename)
return is_uploaded_file($filename);
* 取得上传文件的后缀
private function getExt($filename)
$pathinfo = pathinfo($filename);
return $pathinfo['extension'];
* 取得上传文件的信息
public function getUploadFileInfo()
return $this-uploadFileInfo;
* 取得最后一次错误信息
public function getErrorMsg()
return $this-error;
}//类定义结束
这篇文章主要介绍了php多文件上传实现代码,需要的朋友可以参考下
index_uploads.php
代码如下:
html
head
meta
titleindex_uploads/title
/head
body
form
action="uploads.php"
method="post"
enctype="multipart/form-data"
input
type="file"
name="file[]"
br
type="submit"
value="uploads"
/form
/body
/html
uploads.php
echo
"pre";
print_r($_FILES);
"/pre";
$count
=
count($_FILES['file']['name']);
for
($i
0;
$i
$count;
$i++)
$tmpfile
$_FILES['file']['tmp_name'][$i];
$filefix
array_pop(explode(".",
$_FILES['file']['name'][$i]));
$dstfile
"uploads/files/".time()."_".mt_rand().".".$filefix;
if
(move_uploaded_file($tmpfile,
$dstfile))
"scriptalert('succeed!');window.location.href='index_uploads.php';/script";
else
"scriptalert('fail!');window.location.href='index_uploads.php';/script";
核心:1上传首页中input的name属性是这么设置的.
简单 上传什么都可以
upload.html:
form enctype="multipart/form-data" action="upload.php" method="POST"
input name="userfile1" type="file" /br /
input name="userfile1" type="file" /br /
input name="userfile1" type="file" /br /
input type="submit" value="上传" /
upload.php:
$uploaddir = 'uploads/'; //上传的目录
$uploadfile1 = $uploaddir.$_FILES['userfile1']['name'];
if($_FILES['userfile1']['name']!=""){
move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1);
不明白问我好了
以上就是土嘎嘎小编为大家整理的文件上传php数据库源码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!