HTTP_Upload->moveTo upgrade request
| From: | Alex Hayes | Date: | Fri, 03 Oct 2003 00:46:39 +0000 |
| Subject: | HTTP_Upload->moveTo upgrade request | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-22335@lists.php.net to get a copy of this message | ||
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