cvs: pear /HTTP_Upload Upload.php
| From: | Christian Wenz | Date: | Tue, 03 Aug 2004 13:42:11 +0000 |
| Subject: | cvs: pear /HTTP_Upload Upload.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-22520@lists.php.net to get a copy of this message | ||
wenz Tue Aug 3 09:42:11 2004 EDT
Modified files:
/pear/HTTP_Upload Upload.php
Log:
Implemented feature request #1993 (thanks to Markus Tacker).
No the CHMOD of uploaded files (default: 0660) can be set using setChmod().
http://cvs.php.net/diff.php/pear/HTTP_Upload/Upload.php?r1=1.40&r2=1.41&ty=u
Index: pear/HTTP_Upload/Upload.php
diff -u pear/HTTP_Upload/Upload.php:1.40 pear/HTTP_Upload/Upload.php:1.41
--- pear/HTTP_Upload/Upload.php:1.40 Tue Aug 3 08:59:26 2004
+++ pear/HTTP_Upload/Upload.php Tue Aug 3 09:42:11 2004
@@ -7,7 +7,7 @@
//
// **********************************************
//
-// $Id: Upload.php,v 1.40 2004/08/03 12:59:26 wenz Exp $
+// $Id: Upload.php,v 1.41 2004/08/03 13:42:11 wenz Exp $
/*
* Pear File Uploader class. Easy and secure managment of files
@@ -20,7 +20,7 @@
* - try to think a way of having all the Error system in other
* file and only include it when an error ocurrs
*
- * -- Notes for users HTTP_Upload >= 0.9.0 --
+ * -- Notes for users HTTP_Upload >= 1.0.0 --
*
* Error detection was enhanced, so you no longer need to
* check for PEAR::isError() in $upload->getFiles() or call
@@ -32,7 +32,7 @@
* $upload = new HTTP_Upload('en');
* $file = $upload->getFiles('i_dont_exist_in_form_definition');
* if ($file->isError()) {
- * die($file->getMessage());
+ * die($file->getMessage());
* }
*
* --
@@ -42,6 +42,11 @@
require_once 'PEAR.php';
/**
+ * defines default chmod
+ */
+define('HTTP_UPLOAD_DEFAULT_CHMOD', 0660);
+
+/**
* Error Class for HTTP_Upload
*
* @author Tomas V.V.Cox <cox@idecnet.com>
@@ -212,7 +217,7 @@
'DEV_NO_DEF_FILE' => array(
'es' => 'No está definido en el formulario este nombre de
fichero como <input type="file" name=?>.',
'en' => 'This filename is not defined in the form as
<input type="file" name=?>.',
- 'de' => 'Dieser Dateiname ist in der Datei nicht als
<input type="file" name=?> definiert.',
+ 'de' => 'Dieser Dateiname ist im Formular nicht als
<input type="file" name=?> definiert.',
'nl' => 'Deze bestandsnaam is niett gedefineerd in het
formulier als <input type="file" name=?>.'
)
);
@@ -273,6 +278,13 @@
* @var array
*/
var $files = array();
+
+ /**
+ * Contains the desired chmod for uploaded files
+ * @var int
+ * @access private
+ */
+ var $_chmod = HTTP_UPLOAD_DEFAULT_CHMOD;
/**
* Constructor
@@ -327,7 +339,7 @@
'_error', null,
null, null,
null, $files->getCode(),
- $this->lang);
+ $this->lang, $this->_chmod);
} else {
$this->files = $files;
}
@@ -413,7 +425,7 @@
$type = $value['type'][$key];
$formname = $userfile . "[$key]";
$files[$formname] = new HTTP_Upload_File($name, $tmp_name,
- $formname, $type, $size, $error,
$this->lang);
+ $formname, $type, $size, $error,
$this->lang, $this->_chmod);
}
// One file
} else {
@@ -429,7 +441,7 @@
$type = $value['type'];
$formname = $userfile;
$files[$formname] = new HTTP_Upload_File($name, $tmp_name,
- $formname, $type, $size, $error,
$this->lang);
+ $formname, $type, $size, $error,
$this->lang, $this->_chmod);
}
}
return $files;
@@ -464,6 +476,16 @@
}
return false;
}
+
+ /**
+ * Sets the chmod to be used for uploaded files
+ *
+ * @param int Desired mode
+ */
+ function setChmod($mode)
+ {
+ $this->_chmod = $mode;
+ }
}
/**
@@ -513,6 +535,13 @@
var $_extensions_mode = 'deny';
/**
+ * Contains the desired chmod for uploaded files
+ * @var int
+ * @access private
+ */
+ var $_chmod = HTTP_UPLOAD_DEFAULT_CHMOD;
+
+ /**
* Constructor
*
* @param string $name destination file name
@@ -525,7 +554,8 @@
* @access public
*/
function HTTP_Upload_File($name = null, $tmp = null, $formname = null,
- $type = null, $size = null, $error = null, $lang = null)
+ $type = null, $size = null, $error = null,
+ $lang = null, $chmod = HTTP_UPLOAD_DEFAULT_CHMOD)
{
$this->HTTP_Upload_Error($lang);
$ext = null;
@@ -565,6 +595,8 @@
'type' => $type,
'error' => $error
);
+
+ $this->_chmod = $chmod;
}
/**
@@ -722,7 +754,7 @@
if (!@move_uploaded_file($this->upload['tmp_name'], $name_dest)) {
return $this->raiseError('E_FAIL_MOVE');
}
- @chmod($name_dest, 0660);
+ @chmod($name_dest, $this->_chmod);
return $this->getProp('name');
}