0
我有用於上傳正常工作的文件的代碼。將文件上傳到數據庫時,我從另一個數據庫中獲取上傳器的用戶名。我也有一個頁面,我desplay所有上傳的文件,它工作正常。現在我想要一個頁面,用戶只能顯示自己上傳的文件,並且可以刪除它們。我會怎麼做呢?如何讓用戶顯示他們上傳的文件
文件上傳頁面:
<?php
include 'template/overall/header.php';
?>
<br><br>
<div class="row">
<div class="large-12 medium-12 small-12 columns" style="background-color: #000000; text-align: center">
<ul class="side-nav" style="background-color: #EEEEEE; border: 1px solid white;">
<h2>Ladda upp en fil</h2>
<br><br>
<form action="add_file.php" method="POST" enctype="multipart/form-data">
<div class="large-12 medium-12 small-12 columns" style="padding-left: 39%">
<input type="file" name="file" value="Bläddra">
</div>
<br><br>
<div class="large-12 medium-12 small-12 columns" style="padding-left: 41.5%; width: 60%">
<input type="submit" name="upload_file" value="Ladda upp">
</div>
</form>
<br><br><br><p>Gå tillbaka till <a href="filer.php">filer</a></p> <br><br>
</ul>
</div>
</div>
<?php
if(isset($_GET['success']))
{
?>
<br><br><br>
<h2 style="text-align: center; color: #FFFFFF">Din uppladdning lyckades!</h2>
<br>
<p style="text-align: center; color: #FFFFFF; font-size: 120%">Klicka <a href="filer.php">här</a> för att se din fil</a></p>
<?php
}
else if(isset($_GET['fail']))
{
?>
<br><br><br>
<h2 style="text-align: center; color: #FFFFFF">Problem vid uppladning av fil!</h2>
<?php
}
else
{
?>
<br><br><br>
<h2 style="text-align: center; color: #FFFFFF">Testa att ladda upp en fil(PDF, DOC, EXE, VIDEO, MP3, ZIP,etc...)</h2>
<p style="text-align: center; color: #FFFFFF; font-size:120%">Om du laddar upp en stor fil som en film tex vänligen komprimerar till rar</p>
<?php
}
include 'template/overall/footer.php';
?>
文件proccess頁:
<?php
include 'core/init.php';
if(isset($_POST['upload_file']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="filer/mina_filer/";
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
/*if (isset($_POST['upload_file'])) {
$session_user_id = $_SESSION['id'];
$user_id = $user_data['id'];
$query = mysql_query("INSERT INTO file(user_name) SELECT `userName` FROM `users` WHERE `id` = $user_id");
} */
if (isset($_POST['upload_file'])) {
$folder = 'filer/mina_filer/';
$session_user_id = $_SESSION['id'];
$user_name = $user_data['userName'];
move_uploaded_file($file_loc,$folder.$final_file);
$sql="INSERT INTO file(file, user_name, type, size, folder) VALUES('$final_file', '$user_name', '$file_type', '$new_size', '$folder')";
mysql_query($sql);
?>
<script>
alert('uppladdning lyckades!');
window.location.href='ladda_fil.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('Error när filen laddades upp!');
window.location.href='ladda_fil.php?fail';
</script>
<?php
}
}
?>
我希望有一個類似的頁面像這樣將顯示用戶上傳的文件和顯示錶將包括刪除X文件。
<?php
include 'template/overall/header.php';?>
<div class="large-12 medium-12 columns">
<table width="60%" border="1" align="center">
<tr>
<th colspan="4"><label style="text-align: center"><b>Uppladdade filer</b></label><label style="text-align: center"><a href="ladda_fil.php"> Ladda upp en ny fil</a></label></th>
</tr>
<tr>
<td>Fil Namn</td>
<td>Fil Typ</td>
<td>Fil Storlek(KB)</td>
<td>Uppladdad av</td>
<td>Öppna</td>
</tr>
<?php
$sql="SELECT * FROM file";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['size'] ?></td>
<td><?php echo $row['user_name'] ?></td>
<td><a href="filer/mina_filer/<?php echo $row['file'] ?>" target="_blank">Öppna fil</a></td>
</tr>
<?php
}
?>
</table>
</div>
<?php
include 'template/overall/footer.php';
?>
Thanx爲您的答案。這也是我以前的嘗試,但它不想工作。就好像$ username和user_name不一樣,但它們是。 – BriefHeart