Re: Re: HTTP_Upload unique files

From: Date: Sun, 03 Oct 2004 08:12:30 +0000
Subject: Re: Re: HTTP_Upload unique files
References: 1 2 3 4 5 6 7  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33624@lists.php.net to get a copy of this message
Thanks Norbert for your suggestions, very helpful :)
In this case I think renaming should be done when calling moveTo(). This is the only way to make sure that you cannot accidentally pass different directories to setName() and moveTo().
Good Thing to do
I suggest you to do the following: 1. Create a new member variable in the class HTTP_Upload_File. You also have to store prepend & append string that get passed to setName(): var $mode_name_seq = false; var $mode_name_seq_prepend = null; var $mode_name_seq_append = null;
This would pollute the package with anopther 3 variables, wouldn't an array be better. var $mode_name_seq['flag'] = false; //this flag should hold if the user wants a 'seq' naming mode, a different key for the array would be more useful :) var $mode_name_seq['prepend'] var $mode_name_seq['append']
3. Create the function _nameToSeq() which will be called from moveTo() function _nameToSeq($path) { // $path contains your path // file name to rename is in $this->upload['name'] // // don't forget to include $this->mode_name_seq_prepend // and $this->mode_name_seq_prepend // // return $yourfinalname; .. }
Though the name _nameToSeq() is much better, because this is a utility function. I prefer to use nameToSeq(). So that it matches the current naming convention for a similiar function nameToUniq(). Or change both functions and add '_' at the beginning
5. Document that 'seq' is a special mode and it doesn't rename on-the-fly but when calling moveTo(). This way one can use it together with the other renaming methods (I'm not sure though).
I don't think it should be called with other naming methods. but the only naming method that might be combind with 'seq' is 'safe'. I think safe should be a flag for the object rather than a naming mode e.g $_objUpload = new HTTP_Upload('en'); $_objUpload->isNameSafe = true; //or probably make it more decent be using a 'mutator function(setter)' $_objUpload->setNameSafe( true ) this way it can be combined with any naming method
Please note that I'm not the developer of this package and they probably have their own opinion on this.
It would be good if the developer(s) join this discussion
Regards, Norbert
The feedback you have provided so far is very valuable, thanks very much.

« previous php.pear.dev (#33624) next »