Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为每个用户上载的文件取消链接/删除文件(带有复选框)_Php - Fatal编程技术网

Php 为每个用户上载的文件取消链接/删除文件(带有复选框)

Php 为每个用户上载的文件取消链接/删除文件(带有复选框),php,Php,您好,我如何删除每个用户在其帐户中上载的文件。 文件的位置是我的文件夹“uploader/”。 我试图将代码取消链接(“uploader/$row1”); $row1是每个上载文件的文件名 守则: <?php **// Check if delete button active** $delete1 = $_POST['delete']; if(isset($delete1)) { $checkboxID =$_POST['checkbox']; for($i=0;$i<$count

您好,我如何删除每个用户在其帐户中上载的文件。 文件的位置是我的文件夹“uploader/”。 我试图将代码取消链接(“uploader/$row1”); $row1是每个上载文件的文件名

守则:

<?php
**// Check if delete button active**
$delete1 = $_POST['delete'];
if(isset($delete1)) {
$checkboxID =$_POST['checkbox'];
for($i=0;$i<$count;$i++){
$del_id = $checkboxID[$i];
$sql = "DELETE FROM uploadedfiles WHERE fileid='$del_id'";
$result = mysql_query($sql);
}

if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=myfiles.php\">";
$sucdel = "Deletion Successful.";
}

}
mysql_close();
?>

这是一页纸。谢谢您的帮助。


<?php
//loop through an array from check boxes. it wont delete the actual file tho, bad to use coz its possible to delete other peoples files :/
if (isset($_POST["checkbox"])){
    $delArr = $_POST["checkbox"];
    foreach ($delArr as $id) {
        mysql_query('DELETE from uploadedfiles where fileid ="'.$id.'"');
    }
}

//so get the users file list first then loop through and delete each one, then remove the rows

if (isset($_POST["checkbox"]) && isset($_POST['user'])){
    $result = mysql_query('SELECT name from uploadedfiles where username="'.mysql_real_escape_string($_POST['user']).'"');
    if(mysql_num_rows($result)>0){
        while ($row=mysql_fetch_array($result)) {
            unlink('path_to_userfiles/'.$row['uploadedfiles']);
        }
        mysql_query('DELETE FROM uploadedfiles WHERE username ="'.mysql_real_escape_string($_POST['user']).'"');
    }
}
?>

如果您知道文件在哪里,这是可能的。如果没有文件路径(数据库中似乎没有),我们无法知道。。。等等,你的问题是什么?对不起,我很困惑,我到底要把这个放在哪里?这只是一个例子,改编一下。您可以将其放置在其发布到的页面的任何位置。两个示例都会删除所有文件,尽管有复选框。在您的示例中,$db应该是什么?对不起,没什么,我总是将连接放在所有查询的末尾,脏习惯:/i仍然不工作。我试图将$row['uploadedfiles']替换为$row['name'],其中'name'是文件名的名称字段。和mysql_real_escape_string($_POST['user'])插入到处于$_会话(已登录)的用户中。
<?php
include "dbconnect.php";

$sql="SELECT * FROM uploadedfiles";
$result=mysql_query($sql);
$count = mysql_num_rows($result);
$query = mysql_query("SELECT * FROM uploadedfiles WHERE username='$usersess' ");
while ($row=mysql_fetch_array($query)) { 
$row0 = $row['fileid'];
$row1 = $row['name'];
$row2 = $row['size'];
$row3 = $row['type'];
$dlfile = "<a href='download.php?file=$row1'>Download</a>"; 

?>
<?php
//loop through an array from check boxes. it wont delete the actual file tho, bad to use coz its possible to delete other peoples files :/
if (isset($_POST["checkbox"])){
    $delArr = $_POST["checkbox"];
    foreach ($delArr as $id) {
        mysql_query('DELETE from uploadedfiles where fileid ="'.$id.'"');
    }
}

//so get the users file list first then loop through and delete each one, then remove the rows

if (isset($_POST["checkbox"]) && isset($_POST['user'])){
    $result = mysql_query('SELECT name from uploadedfiles where username="'.mysql_real_escape_string($_POST['user']).'"');
    if(mysql_num_rows($result)>0){
        while ($row=mysql_fetch_array($result)) {
            unlink('path_to_userfiles/'.$row['uploadedfiles']);
        }
        mysql_query('DELETE FROM uploadedfiles WHERE username ="'.mysql_real_escape_string($_POST['user']).'"');
    }
}
?>