NYCPHP Meetup

NYPHP.org

[nycphp-talk] protecting download directory in PHP app on Unix box?

Steve Manes smanes at magpie.com
Wed May 28 15:24:12 EDT 2008


Kristina Anderson wrote:
> Hmm...seems quick and easy.  
> 
> I'm not sure how to do that in PHP though, any links to sample code?
> 
> I could use the transaction ID for that, which is what I really want to 
> use somehow, as they are guaranteed unique.

MD5.  Here's a function I use in a file_store class to generate a munged 
directory file path given (for instance) a user's unique ID.

     public function generate_upload_path($id)
     {
         $hash  = md5($id);
         $p1 = substr($hash, 0, 3);
         $p2 = substr($hash, 3, 3);

         return $this->attachments_dir . "/$p1/$p2/$id";
     }



More information about the talk mailing list