Re: HTTP_Upload->moveTo upgrade request
| From: | Tomas V.V.Cox | Date: | Fri, 03 Oct 2003 09:18:19 +0000 |
| Subject: | Re: HTTP_Upload->moveTo upgrade request | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-22345@lists.php.net to get a copy of this message | ||
Please fill a bug report at: http://pear.php.net/package/http_upload.
I'll take care on it, but don't spect to happen soon, sorry.
Tomas V.V.Cox
Friday, October 3, 2003, 2:46:39 AM, Alex Hayes wrote:
> Hi,
> I was wondering if the following functionality could be added so that when
> using HTTP_Upload it is possible to chmod the uploaded file.
> ========8<========
> function moveTo($dir_dest, $overwrite=true, $mode = 0660)
> {
> if (!$this->isValid()) {
> return $this->raiseError($this->upload['error']);
> }
> file://Valid extensions check
> if (!$this->_evalValidExtensions()) {
> return $this->raiseError('NOT_ALLOWED_EXTENSION');
> }
> $err_code = $this->_chk_dir_dest($dir_dest);
> if ($err_code !== false) {
> return $this->raiseError($err_code);
> }
> // Use 'safe' mode by default if no other was selected
> if (!$this->mode_name_selected) {
> $this->setName('safe');
> }
> $name_dest = $dir_dest . DIRECTORY_SEPARATOR .
$this->>upload['name'];
> if (@is_file($name_dest)) {
> if ($overwrite !== true) {
> return $this->raiseError('FILE_EXISTS');
> } elseif (!is_writable($name_dest)) {
> return $this->raiseError('CANNOT_OVERWRITE');
> }
> }
> // Copy the file and let php clean the tmp
> if (!@copy($this->upload['tmp_name'], $name_dest)) {
> return $this->raiseError('E_FAIL_MOVE');
> }
> @chmod($name_dest, $mode);
> return $this->getProp('name');
> }
========>>8========
> For those that know the class they might notice the following changes.
> 1. A function parameter $mode has been added, which defaults to 0660, which
> is what the function previously defaulted to.
> 2. The chmod call at the end of the function uses the value from above
> mentioned parameter, allowing us to now chmod the file to a different value.
> Of course I could just do this to the file manually, but why, when this
> class is already making a call to chmod?
> Does anybody have any objections to this change?
> Thanks
> Alex
--
Tomas V.V.Cox mailto:cox@idecnet.com