[pLog-svn] r1832 - plog/branches/plog-1.0.1/class/file

jondaley at devel.plogworld.net jondaley at devel.plogworld.net
Thu Apr 14 01:02:43 GMT 2005


Author: jondaley
Date: 2005-04-14 01:02:42 +0000 (Thu, 14 Apr 2005)
New Revision: 1832

Modified:
   plog/branches/plog-1.0.1/class/file/fileuploads.class.php
Log:
fixes broken PHP move_uploaded_file function, that doesn't seem to work across partitions. See http://bugs.plogworld.net/view.php?id=424

Modified: plog/branches/plog-1.0.1/class/file/fileuploads.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/file/fileuploads.class.php	2005-04-13 22:19:28 UTC (rev 1831)
+++ plog/branches/plog-1.0.1/class/file/fileuploads.class.php	2005-04-14 01:02:42 UTC (rev 1832)
@@ -53,7 +53,8 @@
 			//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)) {
+			if( $this->my_move_uploaded_file( $upload->getTmpName(), 
+			                                   $destinationFolder.basename($upload->getTmpName()))){//$fileName)) {
                	$upload->setFolder( $destinationFolder );
 				$error = 0;
             }
@@ -91,7 +92,7 @@
         	foreach( $this->_files as $file ) {
                 $upload = new FileUpload( $file );
                 $fileName = $upload->getFileName();
-                if( move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
+                if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$fileName)) {
                 	$upload->setFolder( $destinationFolder );
                     $upload->setError( 0 );
                 }
@@ -102,6 +103,39 @@
             }
 
             return $uploads;
-        }
+        }
+        
+        /**
+         * Implements the a move_uploaded_file that handles multiple partitions.
+         *
+         * @return a boolean that indicates if the file was successfully moved.  This will 
+         * return false if the file is not an uploaded file.
+         */
+         function my_move_uploaded_file( $filename, $destination )
+         {
+            // first check to make sure that this file is an uploaded file
+            if ( !is_uploaded_file($filename) )
+            {
+                // This file was not an uploaded file, return false
+                return FALSE;
+            }
+            
+            // Now copy the file to the new location
+            if (!copy($filename, $destination)) {
+                // The copy failed, return false
+                return FALSE;
+            }
+            
+            // Now delete the old file
+            // NOTICE, we are not checking the error here.  It is possible 
+            // the the original file will remain and the copy will exist.
+            //
+            // One way to potentially fix this is to look at the result of unlink, and 
+            // then delete the copy if unlink returned FALSE, but this call to unlink 
+            // could just as easily fail
+            unlink( $filename );
+            
+            return TRUE;
+         }
     }
 ?>




More information about the pLog-svn mailing list