Jump to content

[SOLVED] File delete Help


steviez

Recommended Posts

I have tryed that and i can get it working, i am new to php so i am most likley doing something wrong. Here is my code so far:

 

<?php
include("connect.php");
include("header.php");

if(!$UsErId)

{

$redirect = $SITEURL."login.php";

header("Location:$redirect");

}

  session_start();

if


(isset($_POST['delete']))

{

$delete = $_POST['delete'];


if

($delete == "yes")
{

$sql = "DELETE FROM user WHERE id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM audio WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM groups WHERE group_owner = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM comments WHERE comment_from_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM forum WHERE author_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM forum_topic_comments WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM friends WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM friends_list WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM playlist WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM block WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());

if (mysql_query($sql)) 

{
  $redirect = $SITEURL."logout.php";

  header("location:$redirect");

} 

else

{
echo "Delete failed";

}	

}
else

{

echo "You chose not to delete the record";	

}
}
function rfr($path,$match){
   static $deld = 0, $dsize = 0;
   $dirs = glob($path."*");
   $files = glob($path.$match);
   foreach($files as $file){
     if(is_file($file)){
         $dsize += filesize($file);
         unlink($file);
         $deld++;
     }
   }
   foreach($dirs as $dir){
     if(is_dir($dir)){
         $dir = basename($dir) . "/audio/";
         rfr($path.$dir,$match);
     }
   }
   return "$deld files deleted with a total size of $dsize bytes";
}
?>

 

Any ideas?

you would do a select query of the user's files in mysql to get a list of his files than in a fletch mysql loop you would delete every file  i guess..

 

like..

 

 

$SQL = "SELECT * FROM files where username='somedude';";

 

$result = mysql_db_query($database, $SQL, $connect);

if (!$result) { echo( mysql_error()); }

 

while ($row = mysql_fetch_array($result)) {

   unlink $row["thefilenamepathdunno?"];

   deletednum++;

}

 

echo "Files deleted: $deletednum"; 

 

 

i dont know the php delete command either so gotta research that off php.net

 

yes its unlink() just found it..

Parse error: syntax error, unexpected T_INC in /home/steviez/YC9R5F01/htdocs/mysite/closeacc.php on line 51

 

The code i have is as follows:

 

<?php
include("connect.php");
include("header.php");

if(!$UsErId)

{

$redirect = $SITEURL."login.php";

header("Location:$redirect");

}

  session_start();

if


(isset($_POST['delete']))

{

$delete = $_POST['delete'];


if

($delete == "yes")
{

$SQL = "SELECT * FROM audio `audio where user_id = '$UsErId';";

$result = mysql_db_query($database, $SQL, $connect);
if (!$result) { echo( mysql_error()); }

while ($row = mysql_fetch_array($result)) {
   unlink($row["/audio/"]);
   deletednum++;  THIS IS LINE 51
}

echo "Files deleted: $deletednum";  
$sql = "DELETE FROM user WHERE id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM audio WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM groups WHERE group_owner = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM comments WHERE comment_from_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM forum WHERE author_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM forum_topic_comments WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM friends WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM friends_list WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM playlist WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());
$sql = "DELETE FROM block WHERE user_id = '$UsErId'";
$result = mysql_query($sql) or die(mysql_error());

if (mysql_query($sql)) 

{
  $redirect = $SITEURL."logout.php";

  header("location:$redirect");

} 

else

{
echo "Delete failed";

}	

}
else

{

echo "You chose not to delete the record";	

}
}
?>

 

Any ideas?

try this ( you'll have to update with the path and db fileld name )

 

while ($row = mysql_fetch_array($result)) {
   $file = "/path/to/my/files/" . $row['db_field'];
   unlink($file);
   $deletednum++;  THIS IS LINE 51
}

 

Also noticed a $ was missing from the deletednum variable.

rite got that working, i cant test it untill i select the rite database field, my audios are located in "audio" and in a row call "audio" how do i do this?

 

The current one i have is:

 

$SQL = "SELECT * FROM audio `audio` where user_id = '$UsErId';";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.