SOURCES: php-pear-HTTP_Upload-cvs.patch (NEW) - updates from upstr...

glen glen at pld-linux.org
Wed Feb 22 13:03:54 CET 2006


Author: glen                         Date: Wed Feb 22 12:03:54 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- updates from upstream CVS

---- Files affected:
SOURCES:
   php-pear-HTTP_Upload-cvs.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/php-pear-HTTP_Upload-cvs.patch
diff -u /dev/null SOURCES/php-pear-HTTP_Upload-cvs.patch:1.1
--- /dev/null	Wed Feb 22 13:03:54 2006
+++ SOURCES/php-pear-HTTP_Upload-cvs.patch	Wed Feb 22 13:03:49 2006
@@ -0,0 +1,350 @@
+without locale messages addon from
+http://cvs.php.net/viewcvs.cgi/pear/HTTP_Upload/Upload.php?r1=1.42&r2=1.53&view=patch
+
+--- Upload.php	2004/08/08 09:37:50	1.42
++++ Upload.php	2006/02/11 17:45:50	1.53
+@@ -280,6 +311,13 @@
+     var $files = array();
+     
+     /**
++     * Whether the files array has already been built or not
++     * @var int
++     * @access private
++     */
++    var $is_built = false;
++
++    /**
+      * Contains the desired chmod for uploaded files
+      * @var int
+      * @access private
+@@ -287,6 +325,19 @@
+     var $_chmod = HTTP_UPLOAD_DEFAULT_CHMOD;
+ 
+     /**
++     * Specially used if the naming mode is 'seq'
++	 * Contains file naming information
++     * 
++     * @var array
++     * @access private
++     */
++    var $_modeNameSeq = array(
++        'flag' => false,
++        'prepend' => '',
++        'append' => '',
++    ); 
++
++    /**
+      * Constructor
+      *
+      * @param string $lang Language to use for reporting errors
+@@ -328,22 +379,22 @@
+      */
+     function &getFiles($file = null)
+     {
+-        static $is_built = false;
+         //build only once for multiple calls
+-        if (!$is_built) {
++        if (!$this->is_built) {
+             $files = &$this->_buildFiles();
+             if (PEAR::isError($files)) {
+                 // there was an error with the form.
+                 // Create a faked upload embedding the error
++                $files_code = $files->getCode();
+                 $this->files['_error'] =  &new HTTP_Upload_File(
+                                                        '_error', null,
+                                                        null, null,
+-                                                       null, $files->getCode(),
++                                                       null, $files_code,
+                                                        $this->lang, $this->_chmod);
+             } else {
+                 $this->files = $files;
+             }
+-            $is_built = true;
++            $this->is_built = true;
+         }
+         if ($file !== null) {
+             if (is_int($file)) {
+@@ -362,11 +413,12 @@
+             } else {
+                 // developer didn't specify this name in the form
+                 // warn him about it with a faked upload
+-                return new HTTP_Upload_File(
+-                                           '_error', null,
+-                                           null, null,
+-                                           null, 'DEV_NO_DEF_FILE',
+-                                           $this->lang);
++                $huf =&  new HTTP_Upload_File(
++                                             '_error', null,
++                                             null, null,
++                                             null, 'DEV_NO_DEF_FILE',
++                                             $this->lang);
++                return $huf;
+             }
+         }
+         return $this->files;
+@@ -383,7 +435,8 @@
+         if (!isset($this->content_type) ||
+             strpos($this->content_type, 'multipart/form-data') !== 0)
+         {
+-            return $this->raiseError('BAD_FORM');
++            $error =& $this->raiseError('BAD_FORM');
++            return $error;
+         }
+         // In 4.1 $_FILES isn't initialized when no uploads
+         // XXX (cox) afaik, in >= 4.1 and <= 4.3 only
+@@ -457,11 +510,14 @@
+     function isMissing()
+     {
+         if (count($this->post_files) < 1) {
+-            return $this->raiseError('NO_USER_FILE');
++            $error =& $this->raiseError('NO_USER_FILE');
++            return $error;
+         }
+         //we also check if at least one file has more than 0 bytes :)
+         $files = array();
+         $size = 0;
++        $error = null;
++
+         foreach ($this->post_files as $userfile => $value) {
+             if (is_array($value['name'])) {
+                 foreach ($value['name'] as $key => $val) {
+@@ -469,10 +525,12 @@
+                 }
+             } else {  //one file
+                 $size = $value['size'];
++                $error = $value['error'];
+             }
+         }
+-        if ($size == 0) {
+-            $this->raiseError('NO_USER_FILE');
++        if ($error != 2 && $size == 0) {
++            $error =& $this->raiseError('NO_USER_FILE');
++            return $error;
+         }
+         return false;
+     }
+@@ -525,14 +583,14 @@
+      * @access private
+      * @see HTTP_Upload_File::setValidExtensions()
+      */
+-    var $_extensions_check = array('php', 'phtm', 'phtml', 'php3', 'inc');
++    var $_extensionsCheck = array('php', 'phtm', 'phtml', 'php3', 'inc');
+ 
+     /**
+      * @see HTTP_Upload_File::setValidExtensions()
+      * @var string
+      * @access private
+      */
+-    var $_extensions_mode  = 'deny';
++    var $_extensionsMode  = 'deny';
+ 
+     /**
+      * Contains the desired chmod for uploaded files
+@@ -560,7 +618,7 @@
+         $this->HTTP_Upload_Error($lang);
+         $ext = null;
+ 
+-        if (empty($name) || $size == 0) {
++        if (empty($name) || ($error != 'TOO_LARGE' && $size == 0)) {
+             $error = 'NO_USER_FILE';
+         } elseif ($tmp == 'none') {
+             $error = 'TOO_LARGE';
+@@ -602,7 +660,7 @@
+     /**
+      * Sets the name of the destination file
+      *
+-     * @param string $mode     A valid mode: 'uniq', 'safe' or 'real' or a file name
++     * @param string $mode     A valid mode: 'uniq', 'seq', 'safe' or 'real' or a file name
+      * @param string $prepend  A string to prepend to the name
+      * @param string $append   A string to append to the name
+      *
+@@ -628,6 +686,11 @@
+             case 'real':
+                 $name = $this->upload['real'];
+                 break;
++            case 'seq':
++                $this->_modeNameSeq['flag'] = true;
++                $this->_modeNameSeq['prepend'] = $prepend;
++                $this->_modeNameSeq['append'] = $append;
++                break;
+             default:
+                 $name = $mode;
+         }
+@@ -637,6 +700,46 @@
+     }
+ 
+     /**
++     * Sequence file names in the form: userGuide[1].pdf, userGuide[2].pdf ...
++     *
++     * @param string $dir  Destination directory
++     */
++    function nameToSeq($dir)
++    {
++        //Check if a file with the same name already exists
++        $name = $dir . DIRECTORY_SEPARATOR . $this->upload['real'];
++        if (!@is_file($name)) {
++            return $this->upload['real'];
++        } else {
++            //we need to strip out the extension and the '.' of the file
++            //e.g 'userGuide.pdf' becomes 'userGuide'
++            $baselength = strlen($this->upload['real']) - strlen($this->upload['ext']) - 1;
++            $basename = substr( $this->upload['real'],0, $baselength );
++
++            //here's the pattern we're looking for
++            $pattern = '(\[)([[:digit:]]+)(\])$';
++
++            //just incase the original filename had a sequence, we take it out 
++            // e.g: 'userGuide[3]' should become 'userGuide'
++            $basename =  ereg_replace($pattern, '', $basename);
++        	
++            /*
++             * attempt to find a unique sequence file name
++             */
++            $i = 1;
++        	
++            while (true) {
++                $filename = $basename . '[' . $i . '].' . $this->upload['ext'];
++                $check = $dir . DIRECTORY_SEPARATOR . $filename;
++                if (!@is_file($check)) {
++                    return $filename;
++                }
++                $i++;
++            }
++        }
++    }
++
++    /**
+      * Unique file names in the form: 9022210413b75410c28bef.html
+      * @see HTTP_Upload_File::setName()
+      */
+@@ -660,8 +763,8 @@
+      */
+     function nameToSafe($name, $maxlen=250)
+     {
+-        $noalpha = 'ÁÉÍÓÚÝáéíóúýÂĘÎÔŰâęîôűŔČĚŇŮŕčěňůÄËĎÖÜäëďöü˙ĂăŐőĹĺŃńÇç@°şŞ';
+-        $alpha   = 'AEIOUYaeiouyAEIOUaeiouAEIOUaeiouAEIOUaeiouyAaOoAaNnCcaooa';
++        $noalpha = 'ÁÉÍÓÚÝáéíóúýÂĘÎÔŰâęîôűŔČĚŇŮŕčěňůÄËĎÖÜäëďöü˙ĂăŐőĹĺŃńÇç@°şŞŢţĆć';
++        $alpha   = 'AEIOUYaeiouyAEIOUaeiouAEIOUaeiouAEIOUaeiouyAaOoAaNnCcaooaTtAa';
+ 
+         $name = substr($name, 0, $maxlen);
+         $name = strtr($name, $noalpha, $alpha);
+@@ -715,47 +818,59 @@
+     /**
+      * Moves the uploaded file to its destination directory.
+      *
+-     * @param    string  $dir_dest  Destination directory
+-     * @param    bool    $overwrite Overwrite if destination file exists?
+-     * @return   mixed   True on success or Pear_Error object on error
++     * @param  string  $dir  Destination directory
++     * @param  bool    $overwrite Overwrite if destination file exists?
++     * @return mixed   True on success or PEAR_Error object on error
+      * @access public
+      */
+-    function moveTo($dir_dest, $overwrite = true)
++    function moveTo($dir, $overwrite = true)
+     {
+         if (!$this->isValid()) {
+-            return $this->raiseError($this->upload['error']);
++            $error =& $this->raiseError($this->upload['error']);
++            return $error;
+         }
+ 
+         //Valid extensions check
+         if (!$this->_evalValidExtensions()) {
+-            return $this->raiseError('NOT_ALLOWED_EXTENSION');
++            $error =& $this->raiseError('NOT_ALLOWED_EXTENSION');
++            return $error;
+         }
+ 
+-        $err_code = $this->_chk_dir_dest($dir_dest);
++        $err_code = $this->_chkDirDest($dir);
+         if ($err_code !== false) {
+-            return $this->raiseError($err_code);
++            $error =& $this->raiseError($err_code);
++            return $error;
+         }
+         // 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'];
++        //test to see if we're working with sequence naming mode
++        if ($this->_modeNameSeq['flag'] === true) {
++            $this->upload['name'] = $this->_modeNameSeq['prepend'] . $this->nameToSeq($dir) . $this->_modeNameSeq['append'];
++        }
++
++        $name = $dir . DIRECTORY_SEPARATOR . $this->upload['name'];
+ 
+-        if (@is_file($name_dest)) {
++        if (@is_file($name)) {
+             if ($overwrite !== true) {
+-                return $this->raiseError('FILE_EXISTS');
+-            } elseif (!is_writable($name_dest)) {
+-                return $this->raiseError('CANNOT_OVERWRITE');
++                $error =& $this->raiseError('FILE_EXISTS');
++                return $error;
++            } elseif (!is_writable($name)) {
++                $error =& $this->raiseError('CANNOT_OVERWRITE');
++                return $error;
+             }
+         }
+ 
+         // copy the file and let php clean the tmp
+-        if (!@move_uploaded_file($this->upload['tmp_name'], $name_dest)) {
+-            return $this->raiseError('E_FAIL_MOVE');
+-        }
+-        @chmod($name_dest, $this->_chmod);
+-        return $this->getProp('name');
++        if (!@move_uploaded_file($this->upload['tmp_name'], $name)) {
++            $error =& $this->raiseError('E_FAIL_MOVE');
++            return &error; 
++        }
++        @chmod($name, $this->_chmod);
++        $prop =& $this->getProp('name');
++        return $prop;
+     }
+ 
+     /**
+@@ -764,15 +879,15 @@
+      * @param    string  $dir_dest Destination dir
+      * @return   mixed   False on no errors or error code on error
+      */
+-    function _chk_dir_dest($dir_dest)
++    function _chkDirDest($dir_dest)
+     {
+         if (!$dir_dest) {
+             return 'MISSING_DIR';
+         }
+-        if (!@is_dir ($dir_dest)) {
++        if (!@is_dir($dir_dest)) {
+             return 'IS_NOT_DIR';
+         }
+-        if (!is_writeable ($dir_dest)) {
++        if (!is_writeable($dir_dest)) {
+             return 'NO_WRITE_PERMS';
+         }
+         return false;
+@@ -826,8 +941,8 @@
+      */
+     function setValidExtensions($exts, $mode = 'deny')
+     {
+-        $this->_extensions_check = $exts;
+-        $this->_extensions_mode  = $mode;
++        $this->_extensionsCheck = $exts;
++        $this->_extensionsMode  = $mode;
+     }
+ 
+     /**
+@@ -838,9 +953,9 @@
+      */
+     function _evalValidExtensions()
+     {
+-        $exts = $this->_extensions_check;
++        $exts = $this->_extensionsCheck;
+         settype($exts, 'array');
+-        if ($this->_extensions_mode == 'deny') {
++        if ($this->_extensionsMode == 'deny') {
+             if (in_array($this->getProp('ext'), $exts)) {
+                 return false;
+             }
================================================================


More information about the pld-cvs-commit mailing list