Delete file from directory after download

Talk about Image/File fields (uploading, problems etc.)

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

gregkoron
Senior
Senior
Posts: 29
Joined: Oct 23rd, '09, 13:36

Delete file from directory after download

Postby gregkoron » Feb 9th, '10, 16:32

Hi guys, i want to unlink the files that stored in the exporting directory i've made ( exports/ ) but i dont know where to place the function. I think that the right time and place is when users finish the download. Does anyone know where is the code for the popup window? Any help or ideas except onClose event would be greatly appreciated.

Thanks in advance!

administrator
Site Admin
Site Admin
Posts: 5990
Joined: Jan 7th, '09, 23:18
Contact:

Re: Delete file from directory after download

Postby administrator » Feb 11th, '10, 10:53

Do you want to delete file after download will be completed?
So you need this file only for 1 time? You cannot do it in the save window, where you download it, you have to add new icon in control bar that will delete the file.

gregkoron
Senior
Senior
Posts: 29
Joined: Oct 23rd, '09, 13:36

Re: Delete file from directory after download

Postby gregkoron » Feb 15th, '10, 18:42

Thanks for your reply, i tried some ideas but finally i solved it by adding the following on my index, when a new user visits my site, the files that exist in exports directory over on day are being deleted.

Code: Select all

$days=1;
$dir = 'xxx\\xxx\\xxx\\xxx\\xxx\\exports\\';
if ($handle = opendir($dir))
{
   while (false !== ($file = readdir($handle)))
   {
      if ($file[0] == '.' || is_dir("$dir/$file"))
      {
         // ignore hidden files and directories
         continue;
      }
      $compdir=$dir.$file;
      //echo filemtime($compdir);
      //echo "<br/>";

      if ((time() - filemtime($compdir)) > ($days *86400))
      {
         //echo (time() - filemtime($compdir));
         //echo "<br/>";
         //echo filemtime($compdir);
         unlink("$compdir");
      }
   }
   closedir($handle);
}

If anyone has a better way to do that it would be appreciated!


Return to “Field type: "image/file"”