The current repo belongs to Closed status, and some functions are restricted. For details, please refer to the description of repo status
2 Star 2 Fork 1

闪电侠的右手/php网站实现文件上传管理
Closed

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
css
files
fonts
images
js
login
test
user
about.php
admin_add_company.php
admin_add_user.php
admin_contact.php
admin_file.php
admin_user.php
capital.php
chartConvNum.php
contact.php
creatfold.php
db.php
delete.php
delete_msg.php
file_search.php
firstCharacter.php
gallery.php
index.html
index1.php
input_class.php
internetjc.sql
judge_add_files.php
judge_add_user.php
judge_com.php
reply.php
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
judge_add_files.php 2.76 KB
Copy Edit Raw Blame History
fansOfTech authored 7 years ago . first commit
<?php
session_start();
//var_dump($_SESSION['username']);
if($_SESSION['username']==""){echo "<script language='javascript'>;alert('请登录账户后操作');location.href='login/login.php'</script>";}
else if($_SESSION['class']=="0"){echo "<script language='javascript'>;alert('请使用管理员身份登录');location.href='login/login.php'</script>";}
?>
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "错误码: " . $_FILES["file"]["error"] . "<br />";
if($_FILES['userfile']['error']==4) echo "<script language='javascript'>;alert('没有文件被上传');location.href='admin_file.php'</script>";
if($_FILES['userfile']['error']==3)echo "<script language='javascript'>;alert('文件只有部分被上传');location.href='admin_file.php'</script>";
if($_FILES['userfile']['error']==2) echo "<script language='javascript'>;alert('上传文件的大小超过了限制');location.href='admin_file.php'</script>";
echo "<script language='javascript'>;alert('{$_FILES["file"]["name"]}已经存在');location.href='admin_file.php'</script>";
}
else
{
include("db.php");
include("input_class.php");
$b=new input();
$file=$b->post('file');
$id=$b->post('company'); //post得到的是select发来的value值
/*查询company数据表*/
$sql="SELECT company from company WHERE id='{$id}' ";
$mysqli_result=$mysqli->query($sql);
//var_dump($mysqli_result);
/*通过id得到company字段*/
if($row=$mysqli_result->fetch_array()){
$company=$row['company'];
}
//var_dump($company);
mysqli_free_result($mysqli_result);
/*
*
*创建文件夹及上传文件
*
*/
//header("Content-type:text/html;charset=utf-8");
//要创建的多级目录$path
//判断目录存在否,存在给出提示,不存在则创建目录
$path='files/'.$company;
if (!is_dir(iconv("UTF-8", "GBK", $path))){ //如果目录不存在
mkdir(iconv("UTF-8", "GBK", $path),0777,true);
}
$toFileName =$path.'/'.$_FILES['file']['name'];
$re=move_uploaded_file($_FILES["file"]["tmp_name"],
iconv("UTF-8","gb2312",$toFileName));
if($re){
/*
**插入数据库
*/
$size=round($_FILES['file']['size']/1024,2)."KB";
$sql2="INSERT INTO upload (`fname`,`fpath`,`fsize`,`company`)
values ('{$_FILES['file']['name']}','{$toFileName}','{$size}','{$company}')";
$mysqli_result2=$mysqli->query($sql2);
//var_dump($sql2);
//var_dump($mysqli_result2);
echo "<script language='javascript'>;alert('{$_FILES["file"]["name"]}上传成功');
location.href='admin_file.php'</script>";
//echo ss;
}
else{
echo "<script language='javascript'>;alert('{$_FILES["file"]["name"]}上传失败');
location.href='admin_file.php'</script>";
}
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/shaoeric/php_web_site_implementation_of_file_upload_management.git
git@gitee.com:shaoeric/php_web_site_implementation_of_file_upload_management.git
shaoeric
php_web_site_implementation_of_file_upload_management
php网站实现文件上传管理
master

Search