[pLog-svn] r907 - plog/trunk/class/file

mark at devel.plogworld.net mark at devel.plogworld.net
Tue Feb 1 09:21:33 GMT 2005


Author: mark
Date: 2005-02-01 09:21:32 +0000 (Tue, 01 Feb 2005)
New Revision: 907

Modified:
   plog/trunk/class/file/fileuploads.class.php
Log:
Fix chinese file name upload error in windows server.
http://bugs.plogworld.net/view.php?id=188

Modified: plog/trunk/class/file/fileuploads.class.php
===================================================================
--- plog/trunk/class/file/fileuploads.class.php	2005-02-01 05:06:56 UTC (rev 906)
+++ plog/trunk/class/file/fileuploads.class.php	2005-02-01 09:21:32 UTC (rev 907)
@@ -1,106 +1,108 @@
-<?php
-
-    /**
-     * @package file
-     */
-
-
-	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
-    include_once( PLOG_CLASS_PATH."class/file/fileupload.class.php" );
-
-	define( "FILE_UPLOADS_NOT_ENABLED", -200 );
-
-	/**
-     * Handles file uploads in pLog.
-     */
-	class FileUploads extends Object {
-
-    	var $_files;
-        var $_blogInfo;
-
-    	/**
-         * Creates a new object to handle file uploads. $files is either the
-         * contents of the $_FILES variable (if using PHP >= 4.1.0) or
-         * $HTTP_POST_FILES if earlier version.
-         *
-         * @param files The contents of the array generated by php after a file
-         * has been uploaded.
-         */
-    	function FileUploads( $files )
-        {
-        	$this->Object();
-
-            $this->_files = $files;
-        }
-		
-		/**
-		 * processes only one FileUpload object instead of the whole bunch
-		 *
-		 * @param uplaod A FileUpload object
-		 * @param destinationFolder the destination folder
-		 * @return true if successful or false otherwise
-		 */
-		function processFile( $upload, $destinationFolder ) 
-		{
-        	// first, check if the upload feature is available
-            $config =& Config::getConfig();
-            if( !$config->getValue( "uploads_enabled" )) {
-            	return FILE_UPLOADS_NOT_ENABLED;
-            }
-			
-            if( $destinationFolder[strlen($destinationFolder-1)] != "/" )
-            	$destinationFolder .= "/";
-				
-			$fileName = $upload->getFileName();
-			if( move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
-               	$upload->setFolder( $destinationFolder );
-				$error = 0;
-            }
-            else {
-				$error = 1;
-			}				
-			
-			$upload->setError( $error );
-			
-			return $error;
-		}
-
-        /**
-         * Goes through the array of files and processes them accordingly.
-         * The result is an array of the appropiate Resource class that has been
-         * created using the ResourceFactory class.
-         *
-         * @return An array of Upload objects that have already been moved to a safer
-         * location.
-         */
-        function process( $destinationFolder )
-        {
-        	// first, check if the upload feature is available
-            $config =& Config::getConfig();
-            if( !$config->getValue( "uploads_enabled" )) {
-            	return FILE_UPLOADS_NOT_ENABLED;
-            }
-
-        	// array used to store the files that have already been saved
-        	$uploads = Array();
-
-            if( $destinationFolder[strlen($destinationFolder-1)] != "/" )
-            	$destinationFolder .= "/";
-
-        	foreach( $this->_files as $file ) {
-                $upload = new FileUpload( $file );
-                $fileName = $upload->getFileName();
-                if( move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
-                	$upload->setFolder( $destinationFolder );
-                    $upload->setError( 0 );
-                }
-                else {
-                	$upload->setError( 1 );
-                }
-                array_push( $uploads, $upload );
-            }
-
-            return $uploads;
-        }
-    }
-?>
+<?php
+
+    /**
+     * @package file
+     */
+
+
+	include_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+    include_once( PLOG_CLASS_PATH."class/file/fileupload.class.php" );
+
+	define( "FILE_UPLOADS_NOT_ENABLED", -200 );
+
+	/**
+     * Handles file uploads in pLog.
+     */
+	class FileUploads extends Object {
+
+    	var $_files;
+        var $_blogInfo;
+
+    	/**
+         * Creates a new object to handle file uploads. $files is either the
+         * contents of the $_FILES variable (if using PHP >= 4.1.0) or
+         * $HTTP_POST_FILES if earlier version.
+         *
+         * @param files The contents of the array generated by php after a file
+         * has been uploaded.
+         */
+    	function FileUploads( $files )
+        {
+        	$this->Object();
+
+            $this->_files = $files;
+        }
+		
+		/**
+		 * processes only one FileUpload object instead of the whole bunch
+		 *
+		 * @param uplaod A FileUpload object
+		 * @param destinationFolder the destination folder
+		 * @return true if successful or false otherwise
+		 */
+		function processFile( $upload, $destinationFolder ) 
+		{
+        	// first, check if the upload feature is available
+            $config =& Config::getConfig();
+            if( !$config->getValue( "uploads_enabled" )) {
+            	return FILE_UPLOADS_NOT_ENABLED;
+            }
+			
+            if( $destinationFolder[strlen($destinationFolder-1)] != "/" )
+            	$destinationFolder .= "/";
+				
+			//use basename of tmp_name istead of filename
+			//because there is locale problem with filename
+			//$fileName = $upload->getFileName();
+			if( move_uploaded_file( $upload->getTmpName(), $destinationFolder.basename($upload->getTmpName()))){//$fileName)) {
+               	$upload->setFolder( $destinationFolder );
+				$error = 0;
+            }
+            else {
+				$error = 1;
+			}				
+			
+			$upload->setError( $error );
+			
+			return $error;
+		}
+
+        /**
+         * Goes through the array of files and processes them accordingly.
+         * The result is an array of the appropiate Resource class that has been
+         * created using the ResourceFactory class.
+         *
+         * @return An array of Upload objects that have already been moved to a safer
+         * location.
+         */
+        function process( $destinationFolder )
+        {
+        	// first, check if the upload feature is available
+            $config =& Config::getConfig();
+            if( !$config->getValue( "uploads_enabled" )) {
+            	return FILE_UPLOADS_NOT_ENABLED;
+            }
+
+        	// array used to store the files that have already been saved
+        	$uploads = Array();
+
+            if( $destinationFolder[strlen($destinationFolder-1)] != "/" )
+            	$destinationFolder .= "/";
+
+        	foreach( $this->_files as $file ) {
+                $upload = new FileUpload( $file );
+                $fileName = $upload->getFileName();
+                if( move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
+                	$upload->setFolder( $destinationFolder );
+                    $upload->setError( 0 );
+                }
+                else {
+                	$upload->setError( 1 );
+                }
+                array_push( $uploads, $upload );
+            }
+
+            return $uploads;
+        }
+    }
+?>




More information about the pLog-svn mailing list