Re: Re: HTTP_Upload unique files

From: Date: Sun, 03 Oct 2004 06:51:26 +0000
Subject: Re: Re: HTTP_Upload unique files
References: 1 2 3 4 5 6  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-33623@lists.php.net to get a copy of this message
Ammar Ibrahim wrote:
Normally you would call setName() before MoveTo() , So the sequence wouldn't work, because the sequence is sensitive to the directory that the file should be moved to. A really dumb idea would be to add a parameter to setName() function setName($mode, $prepend = null, $append = null, $path = null) Please suggest something else, as I don't like to change the current API.
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(). 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; 2. Improve setName() to support the new functionality: case 'seq': $this->mode_name_seq = true; $this->mode_name_seq_prepend = $prepend; $this->mode_name_seq_append = $append; break; 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; .. } 4. Modify moveTo() to call _nameToSeq() if needed. Before $name_dest = $dir_dest . DIRECTORY_SEPARATOR . $this->upload['name']; Insert: if ($this->_mode_name_seq) { $this->upload['name'] = $this->_nameToSeq($dir_dest); } 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). Please note that I'm not the developer of this package and they probably have their own opinion on this. Regards, Norbert

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