[MOD] Delete upload after chosen amount of days

Any hacks and modifications will be in here...

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

Postby FrankyM » Sun May 15, 2011 1:29 pm

Hello SamEA,

sorry for my late answer. I got some errors with this code, but now it works for me. I have done some changes.
I made a admin_autodelete.php with this code:
Code: Select all
    <?php
   require_once("./config.php");
    //delete old files
   echo " ******* DFH Autodelete ******* \r\n";
    echo "\r\n__________\r\nDeleting old files...\r\n";
    $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] . ":\r\n";
    fclose($filedata);
        unlink("./files/".$file);
        echo "Deleted /files/" . $file . "\r\n";
        unlink("./storage/".str_replace(".dfh","",$file));
        echo "Deleted /storage/" . str_replace(".dfh","",$file) . "\r\n \r\n";

    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!\r\n \r\n";
   //reset var deletedfiles
   $deletedfiles="";
    echo "\r\n__________\r\nDeleting old images...\r\n";
    $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] . ":\r\n";
    fclose($filedata);
    unlink("./imgfiles/".$file);
    echo "Deleted /imgfiles/" . $file . "\r\n";
    unlink("./images/".str_replace(".dfh","",$file));
    echo "Deleted /images/" . str_replace(".dfh","",$file) . "\r\n \r\n";
    unlink("./thumbs/".str_replace(".dfh","",$file));
    echo "Deleted /thumbs/" . str_replace(".dfh","",$file) . "\r\n \r\n";
    }
    fclose($fh);
    }
    }
    closedir( $dh );
    if (!$deletedfiles) echo "No old images to delete!\r\n";
    //done deleting old files
    die();
    ?>

Run this code in dfh folder:
Code: Select all
php admin_autodelete.php


Works fine for me!

Thx!!!

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 » Sun May 15, 2011 11:19 pm

Great work FrankyM, you can now open this mod as a new topic to assist others with this mod :).

FrankyM wrote:Hello SamEA,

sorry for my late answer. I got some errors with this code, but now it works for me. I have done some changes.
I made a admin_autodelete.php with this code:
Code: Select all
    <?php
   require_once("./config.php");
    //delete old files
   echo " ******* DFH Autodelete ******* \r\n";
    echo "\r\n__________\r\nDeleting old files...\r\n";
    $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] . ":\r\n";
    fclose($filedata);
        unlink("./files/".$file);
        echo "Deleted /files/" . $file . "\r\n";
        unlink("./storage/".str_replace(".dfh","",$file));
        echo "Deleted /storage/" . str_replace(".dfh","",$file) . "\r\n \r\n";

    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!\r\n \r\n";
   //reset var deletedfiles
   $deletedfiles="";
    echo "\r\n__________\r\nDeleting old images...\r\n";
    $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] . ":\r\n";
    fclose($filedata);
    unlink("./imgfiles/".$file);
    echo "Deleted /imgfiles/" . $file . "\r\n";
    unlink("./images/".str_replace(".dfh","",$file));
    echo "Deleted /images/" . str_replace(".dfh","",$file) . "\r\n \r\n";
    unlink("./thumbs/".str_replace(".dfh","",$file));
    echo "Deleted /thumbs/" . str_replace(".dfh","",$file) . "\r\n \r\n";
    }
    fclose($fh);
    }
    }
    closedir( $dh );
    if (!$deletedfiles) echo "No old images to delete!\r\n";
    //done deleting old files
    die();
    ?>

Run this code in dfh folder:
Code: Select all
php admin_autodelete.php


Works fine for me!

Thx!!!

Best regards
Franky
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

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

Postby weawea » Wed Jul 06, 2011 7:05 am

coolguy wrote: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


if I want to to be deleted after 30 days, where I have put the "30"?
weawea
Newbie Member
 
Posts: 4
Joined: Thu Jun 02, 2011 10:17 am

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

Postby SamEA » Wed Jul 06, 2011 12:38 pm

In the SettingsCP, where it says delete file after so many x days of inactivity.
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

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

Postby brijs » Sat Aug 27, 2011 2:33 pm

Hi all,
I agree with what fels is saying.
Thanks.
brijs
Standard Member
 
Posts: 5
Joined: Sat Aug 20, 2011 10:40 am

Previous

Return to Hacks and Modifications

Who is online

Users browsing this forum: No registered users and 0 guests

cron