Skip to content

Commit

Permalink
添加Web端PHP文件
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoubowen-sky committed Aug 31, 2016
1 parent 0863ffa commit 80cae24
Show file tree
Hide file tree
Showing 9 changed files with 2,927 additions and 0 deletions.
118 changes: 118 additions & 0 deletions AndroidDownloadAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
//连接数据库
require_once 'connect.php';
//获取用户输入的文件提取码
$downloadnumber = $_POST['DownLoadNumber'];
//echo $downloadnumber;

if(!$downloadnumber){
echo "This_downloadnumber_is_null";// 没有输入文件提取码!
exit();
}else{
//在数据库中根据输入的提取码查找数据
$sql1 = "select * from fileinfo where downloadnumber = $downloadnumber";
//将查找到的那一行赋值给$query作为资源标识符
$query1 = @mysql_query($sql1);
//echo $query;
//获取资源标识符$query所指向的对象,也就是所要查找的这一行
$arr1 = @mysql_fetch_object($query1);//
//如果没有查找到对应的对象,则说明数据库中没有这条数据,$downloadnumber不存在于系统fileinfo数据表里面
if($arr1 == NULL){
echo "This_downloadnumber_is_not_valid";// 此文件提取码无效!
exit();
}
//从$arr对象中获取path的值,并将其赋值给$downloadpath
//$downloadpath = $arr1 -> path;

//echo $downloadpath;
//echo "<script>alert('$downloadpath');window.location.href='index.php'</script>";


/********************以下是将下载相关的记录写入数据库filedownloadrecords********************/
//获取下载的时间
$date_tmp = time();//获取Linux时间戳
$dateline2 = date("Y-m-d H:i:s", $date_tmp+8*60*60);//将时间戳转换为标准时间

$name2 = $arr1 -> name;
$path2 = $arr1 -> path;
$md5name2 = $arr1 -> md5name;
$type2 = $arr1 -> type;
$size2 = $arr1 -> size;
$downloadnumber2 = $arr1 -> downloadnumber;

//下载者的IP
$requestIP = $_SERVER["REMOTE_ADDR"];

//echo $requestIP;


//在用户下载数据库里面重找是否有下载的记录
//$downloadtimes = 0;

$sql2 = "select * from filedownloadrecords where downloadnumber = $downloadnumber";

$query2 = mysql_query($sql2);

$arr2 = mysql_fetch_object($query2);

/**如果下载记录表中没有这条记录,那么久插入这条记录*/
// if ($arr2 == NULL){

$downloadtimes=1;

$insertsql = "insert into filedownloadrecords(name,path,md5name,type,size,downloadnumber,requestIP,downloadtimes,dateline) values ('$name2','$path2','$md5name2','$type2','$size2','$downloadnumber2','$requestIP','$downloadtimes','$dateline2')";
//echo $insertsql;
mysql_query($insertsql);



/**如果有这条记录就判断是否为同一IP,如果是就增加下载次数,如果不是就重新插入一条数据*/
// }else
// {

// if ($requestIP == $arr2 -> requestIP){
// //获取下载记录表中存储的下载次数的数据downloadtimes

// $downloadtimes = $arr2 -> downloadtimes + 1;

// $sql3 = "update filedownloadrecords set downloadtimes = $downloadtimes where downloadnumber = $downloadnumber";

// mysql_query($sql3);
// }else {
// /**不是同一条IP,那个就需要再插入一条数据*/
// $downloadtimes=1;

// $insertsql2 = "insert into filedownloadrecords(name,path,md5name,type,size,downloadnumber,requestIP,downloadtimes,dateline) values ('$name2','$path2','$md5name2','$type2','$size2','$downloadnumber2','$requestIP','$downloadtimes','$dateline2')";;
// //echo $insertsql2;
// mysql_query($insertsql2);

// }

// }


/***********强制让用户下载文件的代码,用Header实现************/
/* $file_dir = 'FilesUpload/';
$file_name = $arr1 -> md5name;
$file = fopen($file_dir . $file_name,"r"); // 打开文件
//输入文件标签
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir . $file_name));
Header("Content-Disposition: attachment; filename=" . $file_name);//最终保存在磁盘上的文件名
// 输出文件内容
echo fread($file,filesize($file_dir . $file_name));
fclose($file);
exit(); */
//返回文件路径,然后在安卓端下载此文件
echo("$path2");


//echo "<script>window.location.href='$downloadpath';window.location.href='index.php'</script>";
}





95 changes: 95 additions & 0 deletions AndroidUploadAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

require_once 'connect.php';
// $target_path = "./androidupload/";//接收文件目录
// $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
// if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
// echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
// } else{
// echo "There was an error uploading the file, please try again!" . $_FILES['uploadedfile']['error'];
// }


$fileInfo = $_FILES['uploadedfile'];
$filename = $fileInfo['name'];
$type = $fileInfo['type'];
$tmp_name = $fileInfo['tmp_name'];
$size = $fileInfo['size'];
$error = $fileInfo['error'];
//文件路径
$path = 'FilesUpload';
//文件后缀名
$ext=pathinfo($filename,PATHINFO_EXTENSION);
//上传者IP
$uploaderIP = $_SERVER["REMOTE_ADDR"];

//将服务器上的临时文件移动指定目录下
//move_uploaded_file($tmp_name,$destination):将服务器上的临时文件移动到指定目录下
//叫什么名字,移动成功返回true,否则返回false
//move_uploaded_file($tmp_name, "uploads/".$filename);
//copy($src,$dst):将文件拷贝到指定目录,拷贝成功返回true,否则返回false
//copy($tmp_name,"uploads/".$filename);

if($error == UPLOAD_ERR_OK){
//确保文件名唯一,防止重名产生覆盖
$uniName = md5(uniqid(microtime(true),true)).'.'.$ext;
//echo $uniName;exit;
$destination = $path.'/'.$uniName;
if(@move_uploaded_file($tmp_name,$destination)){
//echo "<script>alert('文件上传成功!');window.location.href='index.php'</script>";
}else{
//echo "<script>alert('文件上传失败!');window.location.href='index.php'</script>";
exit;
}
}else{
//匹配错误信息
switch($fileInfo['error']){
case 1:
echo '上传文件超过了PHP配置文件中upload_max_filesize选项的值';
break;
case 2:
echo '超过了表单MAX_FILE_SIZE限制的大小';
break;
case 3:
echo '文件部分被上传';
break;
case 4:
echo "<script>alert('没有选择上传文件!');window.location.href='index.php'</script>";
break;
case 6:
echo '没有找到临时目录';
break;
case 7:
case 8:
echo '系统错误';
break;
}
exit;
}

//向数据库中添加文件的信息
//mysql_query("set names utf8");
$downloadpath = "http://115.28.101.196/".$destination;
//echo $downloadpath;

$downloadnumber = rand(100,999999);//生成随机的四位提取码

//判断系统数据库中是否已经有这个提取码


/* while (($sql_downloadnumber = "select * from fileinfo where downloadnumber = $downloadnumber")) {
$downloadnumber = rand(100,999999);
}
*/

$date_tmp = time();//获取Linux时间戳
$dateline = date("Y-m-d H:i:s", $date_tmp+8*60*60);//将时间戳转换为标准时间

$insertsql = "insert into fileinfo(name,path,md5name,type,size,downloadnumber,uploaderIP,dateline) values ('$filename','$downloadpath','$uniName','$ext','$size','$downloadnumber','$uploaderIP','$dateline')";
//echo $insertsql;
mysql_query($insertsql);

echo "文件上传成功!文件提取码为:$downloadnumber";



6 changes: 6 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
//header是为了防止乱码
header('content-type:text/html;charset=utf-8');
define('HOST', '127.0.0.1');
define('USERNAME', 'root');
define('PASSWORD', 'root');
14 changes: 14 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once 'config.php';
//连接数据库,资源标识符$con,@可以隐藏警告
if(!($con = @mysql_connect(HOST,USERNAME,PASSWORD))){
echo "连接数据库失败";
}
//选择数据库
if(!(mysql_select_db('uploadfileinfo'))){
echo "<br>选择数据库失败";
}
//设定字符集
if(!(mysql_query('set names utf8'))){
echo "<br>设定字符集失败";
}
Binary file added favicon.ico
Binary file not shown.
21 changes: 21 additions & 0 deletions feedback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
//连接数据库
require_once 'connect.php';
//获取用户反馈的信息
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$usersuggestion = $_POST['usersuggestion'];

//上传者IP
$uploaderIP = $_SERVER["REMOTE_ADDR"];


$date_tmp = time();//获取Linux时间戳
$dateline = date("Y-m-d H:i:s", $date_tmp+8*60*60);//将时间戳转换为标准时间


//向数据库中添加数据
$insertsql = "insert into feedback(username,useremail,usersuggestion,uploaderIP,dateline) values ('$username','$useremail','$usersuggestion','$uploaderIP','$dateline')";
echo $insertsql;
mysql_query($insertsql);
//echo "000000000000";
Loading

0 comments on commit 80cae24

Please sign in to comment.