Strategy for creating files and then cleaning up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    Strategy for creating files and then cleaning up

    Hi,

    I'm using PHP 4.3. There is a section of my application in which I'd
    like users to be able to download a custom file. The file would be
    different for each user, so I was planning on creating it on the fly
    when they click "Download". However, I would like to delete the file
    from the server a certain period of time after they've downloaded it.
    (It's a 3 or 4K file). How can I do this?

    Thanks, - Dave

  • Erwin Moller

    #2
    Re: Strategy for creating files and then cleaning up

    laredotornado@z ipmail.com wrote:
    Hi,
    >
    I'm using PHP 4.3. There is a section of my application in which I'd
    like users to be able to download a custom file. The file would be
    different for each user, so I was planning on creating it on the fly
    when they click "Download". However, I would like to delete the file
    from the server a certain period of time after they've downloaded it.
    (It's a 3 or 4K file). How can I do this?
    >
    Thanks, - Dave
    Hi Dave,

    This can be done in several way, but why do you actually create the file?
    You can also just give the user the experience there is a file when (s)he
    clicks the downloadbutton.
    Just let the download-php-script produce the output, just as you do before
    writing the file, and deliver that.

    If that doesn't work for you for some reason, and you absolutely need to
    create a real file, you can do several things to clean them up, the most
    easy:
    - Create a sheduled job (cron on *nix) that checks all possible files and
    check their createdate. If too old, delete.

    Alternatively to a sheduled job, you could use an approach that will do this
    once every 100 times your function is called that creates the file.
    Or every time, but this may get slow if you have a great numbers of files.

    Regards,
    Erwin Moller

    Comment

    • Rik

      #3
      Re: Strategy for creating files and then cleaning up

      laredotornado@z ipmail.com wrote:
      Hi,
      >
      I'm using PHP 4.3. There is a section of my application in which I'd
      like users to be able to download a custom file. The file would be
      different for each user, so I was planning on creating it on the fly
      when they click "Download". However, I would like to delete the file
      from the server a certain period of time after they've downloaded it.
      (It's a 3 or 4K file). How can I do this?
      filemtime() could be used for this.

      However, if your file is made dynamically, and downloaded only by a specific
      user, is there any reason to save it as a file to begin with? With proper
      headers and PHP output you can just dynamically create/'fake' the file each
      time it is required, without having to save it, track it, and clean it up.

      Grtz,
      --
      Rik Wasmus


      Comment

      • laredotornado@zipmail.com

        #4
        Re: Strategy for creating files and then cleaning up

        I want the users to download a file with an ".html" extension. What
        kind of headers would I use to save creating that on a server and have
        that downloaded right to the Desktop (or whereever their default save
        location is)?

        Thanks, -

        Rik wrote:
        laredotornado@z ipmail.com wrote:
        Hi,

        I'm using PHP 4.3. There is a section of my application in which I'd
        like users to be able to download a custom file. The file would be
        different for each user, so I was planning on creating it on the fly
        when they click "Download". However, I would like to delete the file
        from the server a certain period of time after they've downloaded it.
        (It's a 3 or 4K file). How can I do this?
        >
        filemtime() could be used for this.
        >
        However, if your file is made dynamically, and downloaded only by a specific
        user, is there any reason to save it as a file to begin with? With proper
        headers and PHP output you can just dynamically create/'fake' the file each
        time it is required, without having to save it, track it, and clean it up.
        >
        Grtz,
        --
        Rik Wasmus

        Comment

        • Alvaro G. Vicario

          #5
          Re: Strategy for creating files and then cleaning up

          *** laredotornado@z ipmail.com escribió/wrote (3 Jul 2006 13:41:15 -0700):
          I want the users to download a file with an ".html" extension. What
          kind of headers would I use to save creating that on a server and have
          that downloaded right to the Desktop (or whereever their default save
          location is)?
          header('Content-Type: text/html');
          header('Content-Length:' . filesize(...... ..));
          header('Content-Disposition: attachment; filename="..... ......"');

          Another option:

          header('Content-Type: application/octet-stream');


          --
          -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          ++ Mi sitio sobre programación web: http://bits.demogracia.com
          +- Mi web de humor con rayos UVA: http://www.demogracia.com
          --

          Comment

          • chris.g.wood@gmail.com

            #6
            Re: Strategy for creating files and then cleaning up

            laredotornado@z ipmail.com wrote:
            Hi,
            >
            I'm using PHP 4.3. There is a section of my application in which I'd
            like users to be able to download a custom file. The file would be
            different for each user, so I was planning on creating it on the fly
            when they click "Download". However, I would like to delete the file
            from the server a certain period of time after they've downloaded it.
            (It's a 3 or 4K file). How can I do this?
            >
            Thanks, - Dave
            Think a few have pointed this out, but you don't need to store the
            file, something like:

            header('Content-Type: text/html');
            header('Content-Length:' . filesize(...... ..));
            header('Content-Disposition: attachment; filename="..... ......"');
            // Display what you want to output
            print "Something, Or, Other, just testing, the way this works";
            // Output a new line else everything is all on one line.
            print "\n";
            print "www.whatever.c o.uk";
            print "\n";


            Obviously the script can be changed for each user using a little php.

            I've a collection of useful scripts on a site I put together (nothing
            major, just slowly collecting together things i've written over the
            years).


            C Wood.

            Comment

            Working...