我有一個非常基本的文件上傳頁面。 如果您已經登錄,您會看到一個頁面(myFiles.php),其中有一個由登錄的用戶上傳的文件的表格+每行的刪除按鈕。從服務器和數據庫中刪除文件(PHP)
if ($_SESSION['active'] == true) {
echo "<table class='table'>
<tr>
<th>File name</th>
<th>Added</th>
<th></th>
</tr>";
$query = "SELECT filename, filemtime, username FROM Uploads WHERE username='".$active."' ORDER BY filemtime"; //
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$timestamp = strtotime($row["filemtime"]);
echo "<tr><td>" . $row["filename"]. "</td><td>" . date("d.m.Y",$timestamp). "</td>";
echo "<td><form role='form' action='delete_check.php' method='post' enctype='multipart/form-data'>";
echo "<button type='submit' class='btn btn-default'>Delete</button></form></td>";
echo "</tr>";
}
echo "</table>";
}
我需要知道我怎麼能刪除按鈕連接到某行:我從我的數據庫,在那裏我有這個代碼表上傳(文件名,擴展名,filemtime,用戶名)獲取用戶文件以及如何將參數(文件名和擴展名)傳遞到從數據庫和我的服務器(頁面delete_check.php)中刪除文件的頁面。目前
delete_check.php看起來是這樣的(這是行不通的,因爲我無法通過從delete.php參數):我建議你到一個獨特的自動增量ID添加到每一行
session_start();
$active = $_SESSION['active'];
$con = mysql_connect("database","user","pw");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$file = "upload/".$filename.".".$extension;
unlink($filename);
$query = "DELETE FROM Uploads WHERE filename='".$filename."'";
$delete = MYSQL_QUERY($query);
if ($delete === true) {
echo "Deleted from database ".$filename." extension: " . $extension;
} else {
echo "Not deleted ".$filename." extension: " . $extension;
}
//header("Location: index.php");
把文件名作爲一個輸入隱藏字段在HTML中,值=文件名:) – 2014-12-04 12:55:53