我让父母老师上传(它还包含我上传文件时要显示的用户名)我将同样的东西复制到另一个文件中并根据db和文件进行了一些编辑上传正确,但 user_id为0 [没有记录 user_id 0 ]。这是我的问题,我会请求别人给我一些帮助。
对不起,这是一个巨大的代码,但想显示工作文件。我包含问题的文件位于底部。 感谢
par_upload.php
<html>
<title>File|Mgr</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link href="globe.png" rel="shortcut icon">
<?php
date_default_timezone_set("Asia/Calcutta");
//echo date_default_timezone_get();
?>
<?php
$conn = mysqli_connect("localhost","root","","stu_supervision");
session_start();
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['submit'])!="")
{
$name=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$date = date('Y-m-d H:i:s');
//$caption1=$_POST['caption'];
// $link=$_POST['link'];
$file_error = $_FILES['photo']['error'];
$file_ext = explode('.', $name);
$file_ext = strtolower(end($file_ext));
//$allowed = array('jpg', 'jpeg');
$allowed = array('pdf');
if(in_array($file_ext, $allowed))
{
if($file_error === 0)
{
if(file_exists('files/' . $name))
{
// die('<script type="text/javascript">alert("File with that name already exists.");location.replace("index.php")</script>');
die('<script type="text/javascript">alert("File with that name already exists.");location.replace("par_upload.php")</script>');
}
//if($size <= 2097152) {
//--------WHEN UPLOADING FILE, A UNIQUE ID IS GENERATED IN FILES FOLDER THRU 1ST METHOD -------------------
/// $file_name_new = uniqid('', true) . '.' . $file_ext;
// $file_destination = 'files/' . $file_name_new;
$file_destination = 'files/'.$name ;
move_uploaded_file($temp, $file_destination);
$query=mysqli_query($conn,"INSERT INTO upload (name,date,par_id) VALUES ('$name','$date','".$_SESSION['par_id']."')");
if($query){
// header("location:index.php");
header("location:par_upload.php");
}
else{
die(mysql_error());
}
}
}
else
{
echo '<script language="javascript">';
echo 'alert(" SORRY! YOU ARE ONLY ABLE TO UPLOAD PDF FILES")';
echo '</script>';
}
}
?>
<html>
<body>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css"/>
</head>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
<?php include('dbcon.php'); ?>
<style>
.table tr th{
border:#eee 1px solid;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
table tr td{
border:#eee 1px solid;
color:#000;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
#wb_Form1
{
background-color: #00BFFF;
border: 0px #000 solid;
}
#photo
{
border: 1px #A9A9A9 solid;
background-color: #00BFFF;
color: #fff;
font-family:Arial;
font-size: 20px;
}
</style>
Hi <?=$_SESSION['sess_user'];?>! <br><br>
<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered">
<tr><td><form enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="file" name="photo" id="photo" accept="application/pdf" required="required"></td>
<td><input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</form> <strong>SUBMIT HERE</strong></tr></td></table>
<div class="col-md-18">
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>FILE NAME</th>
<th>Date</th>
<th>username</th>
<!-- <th>Download</th> -->
<!-- <th>Remove</th> -->
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($conn, "select * from `upload` left join `par` on par.par_id=upload.par_id ORDER BY id DESC ");
// $query=mysqli_query($conn, "select * from `upload` left join `par` on par.par_id=upload.par_id where p_username = '".$_SESSION['par_id']."' ORDER BY id DESC ");
if($query === false){
throw new Exception(mysql_error($conn));
}
while($row=mysqli_fetch_array($query)){
$id=$row['id'];
$name=$row['name'];
$date=$row['date'];
$username = $row['p_username'];
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td> <?php echo $row['p_username'] ?></td>
<!-- <td>
<a href="download.php?filename=<?php echo $name;?>" title="click to download">VIEW <!--<span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span>-->
<!-- </a> </td> -->
<!-- <td>
<a onclick="return confirm('Are you sure you want to delete this file? ')" href="delete.php?del=<?php //echo $row['id']?>"><span class="glyphicon glyphicon-trash" style="font-size:20px; color:red"></span></a>
</td> -->
</tr>
<?php }
?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
----------------------------------------------
par_upoad_view.php
<html>
<title>File|Mgr</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link href="globe.png" rel="shortcut icon">
<?php
//date_default_timezone_set("Asia/Calcutta");
//echo date_default_timezone_get();
?>
<?php
/* $conn = mysqli_connect("localhost","root","","stu_supervision");
session_start();
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['submit'])!="")
{
$name=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$date = date('Y-m-d H:i:s');
//$caption1=$_POST['caption'];
// $link=$_POST['link'];
$file_error = $_FILES['photo']['error'];
$file_ext = explode('.', $name);
$file_ext = strtolower(end($file_ext));
//$allowed = array('jpg', 'jpeg');
$allowed = array('pdf');
if(in_array($file_ext, $allowed))
{
if($file_error === 0)
{
if(file_exists('files/' . $name))
{
// die('<script type="text/javascript">alert("File with that name already exists.");location.replace("index.php")</script>');
die('<script type="text/javascript">alert("File with that name already exists.");location.replace("par_upload.php")</script>');
}
//if($size <= 2097152) {
//--------WHEN UPLOADING FILE, A UNIQUE ID IS GENERATED IN FILES FOLDER THRU 1ST METHOD -------------------
/// $file_name_new = uniqid('', true) . '.' . $file_ext;
// $file_destination = 'files/' . $file_name_new;
$file_destination = 'files/'.$name ;
move_uploaded_file($temp, $file_destination);
$query=mysqli_query($conn,"INSERT INTO upload (name,date,par_id) VALUES ('$name','$date','".$_SESSION['par_id']."')");
if($query){
// header("location:index.php");
header("location:par_upload.php");
}
else{
die(mysql_error());
}
}
}
else
{
echo '<script language="javascript">';
echo 'alert(" SORRY! YOU ARE ONLY ABLE TO UPLOAD PDF FILES")';
echo '</script>';
}
}
*/
?>
<html>
<body>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css"/>
</head>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
<?php include('dbcon.php'); ?>
<style>
.table tr th{
border:#eee 1px solid;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
table tr td{
border:#eee 1px solid;
color:#000;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
#wb_Form1
{
background-color: #00BFFF;
border: 0px #000 solid;
}
#photo
{
border: 1px #A9A9A9 solid;
background-color: #00BFFF;
color: #fff;
font-family:Arial;
font-size: 20px;
}
</style>
<!-- <table cellpadding="0" cellspacing="0" border="0" class="table table-bordered">
<tr><td><form enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="file" name="photo" id="photo" accept="application/pdf" required="required"></td>
<td><input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</form> <strong>SUBMIT HERE</strong></tr></td></table>
-->
<div class="col-md-18">
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>FILE NAME</th>
<th>Date</th>
<th>username</th>
<th>Download</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($conn, "select * from `upload` left join `par` on par.par_id=upload.par_id ORDER BY id DESC ");
// $query=mysqli_query($conn, "select * from `upload` left join `par` on par.par_id=upload.par_id where p_username = '".$_SESSION['par_id']."' ORDER BY id DESC ");
if($query === false){
throw new Exception(mysql_error($conn));
}
while($row=mysqli_fetch_array($query)){
$id=$row['id'];
$name=$row['name'];
$date=$row['date'];
$username = $row['p_username'];
?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td> <?php echo $row['p_username'] ?></td>
<td>
<a href="download.php?filename=<?php echo $name;?>" title="click to download">VIEW <!--<span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span>--></a>
</td>
<td>
<a onclick="return confirm('Are you sure you want to delete this file? ')" href="delete.php?del=<?php echo $row['id']?>"><span class="glyphicon glyphicon-trash" style="font-size:20px; color:red"></span></a>
</td>
</tr>
<?php }
?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
---PROBLEM----
*THE IMG OF THE UPLOAD TABLE AND HOW THE STU_ID IS DISPLAYED WHEN FILE IS UPLOADED IS PLACED HERE
<?php
$conn = mysqli_connect("localhost","root","","stu_supervision");
session_start();
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['submit'])!="")
{
$name=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$date = date('Y-m-d H:i:s');
$file_error = $_FILES['photo']['error'];
$file_ext = explode('.', $name);
$file_ext = strtolower(end($file_ext));
$allowed = array('pdf');
if(in_array($file_ext, $allowed))
{
if($file_error === 0)
{
if(file_exists('files1/' . $name))
{
die('<script type="text/javascript">alert("File with that name already exists.");location.replace("abc.php")</script>');
}
$file_destination = 'files1/'.$name ;
move_uploaded_file($temp, $file_destination);
$query=mysqli_query($conn,"INSERT INTO upload1 (name,date,stu_id) VALUES ('$name','$date','".$_SESSION['stu_id']."')");
if($query){
header("location:abc.php");
}
else{
die(mysql_error());
}
}
}
else
{
echo '<script language="javascript">';
echo 'alert(" SORRY! YOU ARE ONLY ABLE TO UPLOAD PDF FILES")';
echo '</script>';
}
}
?>