[MOD] Delete upload after chosen amount of days

Any hacks and modifications will be in here...

[MOD] Delete upload after chosen amount of days

Postby coolguy » Sun Feb 27, 2011 1:59 pm

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
Last edited by coolguy on Sun Mar 13, 2011 10:58 pm, edited 1 time in total.
coolguy
Standard Member
 
Posts: 27
Joined: Sat Feb 26, 2011 9:50 am

Hey people

Postby MEaDave » Fri Mar 11, 2011 5:59 pm

Hey people! I’ll stay by there and follow your discussion. I’m new to this topic, but I’m really interested in it.
MEaDave
Newbie Member
 
Posts: 1
Joined: Fri Mar 11, 2011 5:59 pm
Location: Korea North

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

Postby andreic » Sat Mar 12, 2011 9:48 pm

It's nice to delete after some days without activity on the file
andreic
Newbie Member
 
Posts: 4
Joined: Sat Mar 12, 2011 9:45 pm

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

Postby PeterS » Sat Mar 12, 2011 11:16 pm

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.
PeterS
Global Moderator
 
Posts: 159
Joined: Mon Feb 21, 2011 4:58 am

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

Postby coolguy » Sun Mar 13, 2011 11:01 pm

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.
coolguy
Standard Member
 
Posts: 27
Joined: Sat Feb 26, 2011 9:50 am

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

Postby FrankyM » Thu Apr 07, 2011 4:36 pm

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
FrankyM
Newbie Member
 
Posts: 3
Joined: Thu Apr 07, 2011 12:57 pm

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

Postby fels » Thu Apr 14, 2011 11:54 am

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
fels
Premium
 
Posts: 7
Joined: Fri Apr 01, 2011 12:13 pm

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

Postby PeterS » Sun Apr 17, 2011 8:08 am

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.
PeterS
Global Moderator
 
Posts: 159
Joined: Mon Feb 21, 2011 4:58 am

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

Postby FrankyM » Tue May 03, 2011 7:59 pm

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
FrankyM
Newbie Member
 
Posts: 3
Joined: Thu Apr 07, 2011 12:57 pm

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

Postby SamEA » Tue May 03, 2011 9:16 pm

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();
 }
SamEA,
DaddyScripts' Admin & Developer.

Require a PHP or general IT freelancer? Don't hesitate to PM me.
User avatar
SamEA
Site Admin
 
Posts: 1165
Joined: Sat Feb 19, 2011 7:51 pm

Next

Return to Hacks and Modifications

Who is online

Users browsing this forum: No registered users and 4 guests

cron