Page 1 of 2

[MOD] Delete upload after chosen amount of days

PostPosted: Sun Feb 27, 2011 1:59 pm
by coolguy
This will delete the uploaded file after a x amount of days even if the file has been downloaded. It overrides the default deleting system.
Effected Files
upload.php
admin.php


Okay, open ./upload.php and try to locate this line:
Code: Select all
fwrite($filelist, $rand2 ."|". basename($_FILES['upfile']['name']) ."|". $passkey ."|". $userip ."|". $time."|0|".$description."|".$passwerd."|".$cat."|".$_POST['pprotect']."|\n");


This is the part where PHP writes to the database.

Now you'll have to add the $time variable again at the end of the file.

Example:
Code: Select all
fwrite($filelist, $rand2 ."|". basename($_FILES['upfile']['name']) ."|". $passkey ."|". $userip ."|". $time."|0|".$description."|".$passwerd."|".$cat."|".$_POST['pprotect'] ."|". $time."|\n");


Now the first $time variable is assigned to the last time the file was downloaded, and now we'll assign the last $time variable as being the time it was originally first uploaded.

Now we want to modify the deleting script located in ./admin.php

Find:
Code: Select all
 if ($filedata[4] < $deleteseconds) {


Replace with:

Code: Select all
if ($filedata[9] < $deleteseconds) {


Modification wrote by PeterS
memberlist.php?mode=viewprofile&u=54

Hey people

PostPosted: Fri Mar 11, 2011 5:59 pm
by MEaDave
Hey people! I’ll stay by there and follow your discussion. I’m new to this topic, but I’m really interested in it.

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Sat Mar 12, 2011 9:48 pm
by andreic
It's nice to delete after some days without activity on the file

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Sat Mar 12, 2011 11:16 pm
by PeterS
I agree, however the whole point of deleting after X inactivity of days was to prevent the file host from becoming abused and used for unnecessary storage. If file hosters want to delete files in X amount of days without inactivity, I advise them to clearly state this on their website to avoid an uploader's loss and reliability on that file hoster for their files.

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Sun Mar 13, 2011 11:01 pm
by coolguy
Sorry i wasn't clear in the hack posting. the script already has a built in delete system if the file hasn't been downloaded in a x amount of days. this hack deletes the file even if it has been downloaded.

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Thu Apr 07, 2011 4:36 pm
by FrankyM
Hello all,

maybe not the right place for my question....

How can i use the built in delete function by a cronjob?

Thanks for any hints!

Best reagrds
Franky

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Thu Apr 14, 2011 11:54 am
by fels
It should read [10] not [9], if I am counting right.

A cron job could be scheduled via find and ctime (file creation time).

First check:
find <directory> -name "<pattern>" -ctime <period> -ls

Then delete
find <directory> -name "<pattern>" -ctime <period> -exec rm {} \;

Regards Frank

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Sun Apr 17, 2011 8:08 am
by PeterS
fels wrote:It should read [10] not [9], if I am counting right.

A cron job could be scheduled via find and ctime (file creation time).

First check:
find <directory> -name "<pattern>" -ctime <period> -ls

Then delete
find <directory> -name "<pattern>" -ctime <period> -exec rm {} \;

Regards Frank


Alternatively you can use the code to check and delete inactive files located in the admin.php into another file followed by a cronjob to run every now and then.

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Tue May 03, 2011 7:59 pm
by FrankyM
PeterS wrote:Alternatively you can use the code to check and delete inactive files located in the admin.php into another file followed by a cronjob to run every now and then.


Hello,

i tried this befor i asked here, but it does not work. Can you explain the steps to do it with admin.php?

Yes i know that a can do it by a bash script, but my goal was to do it with the built in function. I am realy the only one who want to do this by a cronjob? Strange... :D

Thanks a lot

Best regards
Franky

Re: [MOD] Delete upload after chosen amount of days

PostPosted: Tue May 03, 2011 9:16 pm
by SamEA
FrankyM wrote:
PeterS wrote:Alternatively you can use the code to check and delete inactive files located in the admin.php into another file followed by a cronjob to run every now and then.


Hello,

i tried this befor i asked here, but it does not work. Can you explain the steps to do it with admin.php?

Yes i know that a can do it by a bash script, but my goal was to do it with the built in function. I am realy the only one who want to do this by a cronjob? Strange... :D

Thanks a lot

Best regards
Franky


Hello,

I have not tested this, but it should work.

Let me know if any errors occur.

Find & Remove the following piece of code located in ./admin.php:
Code: Select all
if(isset($_GET['act']) && $_GET['act']=="deloldfiles") {
?>
<center>
<table width=100% cellspacing=0 cellpadding=0 border=0 bgcolor=#CBD6F3><tr><td background="img/bg.png" align=absmiddle valign=absmiddle>
<font color=#C0C0C0>| <img src="img/blue.gif"> <a href="admin.php?act=logout"><? echo $lang[logout];?></a> | <img src="img/blue.gif"> <a href="admin.php"><? echo $lang[index];?></a>  |  <img src="img/blue.gif"> <a href="admin.php?act=users">Users</a> | <img src="img/blue.gif"> <a href="admin.php?act=files"><? echo $lang[files];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=image"><? echo $lang[images];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=changedlpass"><? echo $lang[master];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=abuse"><? echo $lang[abuse];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=deloldfiles"><? echo $lang[delete];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=bans"><? echo $lang[bans];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=check"><? echo $lang[check];?></a> | <img src="img/blue.gif"> <a href="admin.php?act=info"><? echo $lang[info_1];?></a> | <img src="img/blue.gif"> <a href="settings.php"><? echo $lang[settings];?></a> |
</td></tr></table>
<center><br>
<h1><? echo $lang[delete];?></h1>
<?
//delete old files
echo "Deleting old files...<BR>";
$deleteseconds = time() - ($deleteafter * 24 * 60 * 60);
$dirname = "./files";
$dh = opendir( $dirname ) or die("couldn't open directory");
while ( $file = readdir( $dh ) ) {
if ($file != '.' && $file != '..' && $file != ".htaccess") {
  $fh=fopen("./files/" . $file ,r);
  $filedata= explode('|', fgets($fh));
  if ($filedata[4] < $deleteseconds) {
    $deletedfiles="yes";
    echo "Deleting - " . $filedata[1] . ":<BR>";
fclose($filedata);
    unlink("./files/".$file);
    echo "Deleted /files/" . $file . "<BR>";
    unlink("./storage/".str_replace(".dfh","",$file));
    echo "Deleted /storage/" . str_replace(".dfh","",$file) . "<BR><BR>";

if ($filedata[10] <> "") {
unlink("./userfiles/files/" .$filedata[10] ."/" .$file);
echo "Deleted ./userfiles/files/" .$filedata[10] ."/" .$file;
}
  }
  fclose($fh);
}
}
closedir( $dh );
if (!$deletedfiles) echo "No old files to delete!<br /><br />";
echo "Deleting old files...<BR>";
$deleteseconds = time() - ($deleteafter * 24 * 60 * 60);
$dirname = "./imgfiles";
$dh = opendir( $dirname ) or die("couldn't open directory");
while ( $file = readdir( $dh ) ) {
if ($file != '.' && $file != '..' && $file != ".htaccess") {
$fh=fopen("./imgfiles/" . $file ,r);
$filedata= explode('|', fgets($fh));
if ($filedata[6] <> "") {
unlink("./userfiles/images/" .$filedata[6] ."/" .$file);
}
if ($filedata[4] < $deleteseconds) {
$deletedfiles="yes";
echo "Deleting - " . $filedata[1] . ":<BR>";
fclose($filedata);
unlink("./imgfiles/".$file);
echo "Deleted /imgfiles/" . $file . "<BR>";
unlink("./images/".str_replace(".dfh","",$file));
echo "Deleted /images/" . str_replace(".dfh","",$file) . "<BR>";
unlink("./thumbs/".str_replace(".dfh","",$file));
echo "Deleted /thumbs/" . str_replace(".dfh","",$file) . "<BR><BR>";
}
fclose($fh);
}
}
closedir( $dh );
if (!$deletedfiles) echo "No old images to delete!<br /><br />";
//done deleting old files
echo "</center></td></tr></table><p style=\"margin:3px;text-align:center\">";
include ("./footer.php");
die();
 }