说明:
主要两个文件,很简单但是很有效,文件一可以分解为HTML和PHP文件
然后用PHP文件引用包含HTML文件
文件1:index.php
<?php
header("Content-Type:text/html; charset=utf-8");
include('../../../config/config.php');
$conn = mysqli_connect($_config['db']['1']['dbhost'],$_config['db']['1']['dbuser'],$_config['db']['1']['dbpw']);
if (! $conn) {
die('无法连接数据库:' . mysqli_error());
}
echo "连接数据库成功。";
echo "<pre>";
print_r($_FILES);
echo "</pre>";
$tmpfile = $_FILES['file']['tmp_name'];
$dstfile ="files/" . date('Y_m_d/') .$_FILES['file']['name'];
$file_name_old = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$err_info = $_FILES['file']['error'];
$file_size = ceil($_FILES['file']['size']/1024);
// echo $file_name_old;
// echo $file_type;
// echo $err_info;
// echo $file_size;
// die();
function crt_dir($path, $mode='0777'){
if (!is_dir($path)) {
mkdir($path, $mode, true);
}
}
$dir_name = "files/" . date('Y_m_d/');
crt_dir($dir_name);
if (move_uploaded_file($tmpfile, $dstfile)){
echo "sucess";
}else{
echo "failed";
}
mysqli_query($conn, "set names utf8");
$sql = "insert into pic_to_pc(file_name,file_type,file_tmp_name,err_info,file_size,new_name) values('{$file_name_old}','{$file_type}','{$tmpfile}','{$err_info}','{$file_size}','{$dstfile}')";
mysqli_select_db($conn,$_config['db']['1']['dbname']);
mysqli_query($conn, $sql);
// 下面这行可以删除
mysqli_close($conn);
echo "<br/>aa/plugin/iPhonePicToPC/toPic2.0/files/";
echo "<label><br/><a href='./index.php'>here back</a></label>";
?>
文件2:upload.php
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>iPe Pic upload</title>
<link rel="stylesheet" href="../../../static/bootstrap/bootstrap.min.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<h2>Phone file upload</h2>
<hr>
<form role='form' action="upload.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for='inputfile'>文件输入</label>
<br /><br />
<input class='btn btn-info btn-lg' type='file' name='file' id=''>
</div>
<br />
<button type='submit' class='btn btn-default btn-lg'>提交</button>
</form>
<br />
<div class="table-responsive">
<?php
include('../../../config/config.php');
$conn = mysqli_connect($_config['db']['1']['dbhost'],$_config['db']['1']['dbuser'],$_config['db']['1']['dbpw']);
if (! $conn) {
die('无法连接数据库:' . mysqli_error());
}
// echo "连接数据库成功。";
mysqli_query($conn, "set names utf8");
$sql = "select file_id, file_name, new_name from pic_to_pc ORDER BY file_id DESC LIMIT 0, 5";
mysqli_select_db($conn,$_config['db']['1']['dbname']);
$retval = mysqli_query($conn, $sql);
if (! $retval) {
die('无法读取数据:' . mysqli_error($conn));
}
// echo "<h2>数据库test中tl_url_log表中数据</h2>";
echo "<table class='table table-striped table-bordered'> <thead> <tr> <th>ID</th> <th>NAME</th> </tr> </thead>";
echo "<tbody>";
while ($row = mysqli_fetch_array($retval, MYSQLI_ASSOC)) {
echo "<tr><td>{$row['file_id']}</td>".
"<td><a href='./{$row["new_name"]}'>{$row['file_name']}</a></td></tr>";
}
echo "</tbody> </table>";
mysqli_close($conn);
?>
</div>
</div>
</body>
</html>
需要在MySQL数据库中建立响应数据库和表字段
1.0版本 后续开发为复制粘贴到就可以用的插件模式 source/plugin