Bläddra i källkod

[HttpFoundation] Fixed: File/UploadedFile did not adjust path when moved

Bernhard Schussek 14 år sedan
förälder
incheckning
e9fcacdad7

+ 2 - 0
src/Symfony/Component/HttpFoundation/File/File.php

@@ -573,5 +573,7 @@ class File
         if (!rename($this->getPath(), $newPath)) {
             throw new FileException(sprintf('Could not move file %s to %s', $this->getPath(), $newPath));
         }
+
+        $this->path = realpath($newPath);
     }
 }

+ 1 - 0
src/Symfony/Component/HttpFoundation/File/UploadedFile.php

@@ -117,6 +117,7 @@ class UploadedFile extends File
             }
 
             $this->moved = true;
+            $this->path = realpath($newPath);
         } else {
             parent::move($newPath);
         }

+ 19 - 0
tests/Symfony/Tests/Component/HttpFoundation/File/FileTest.php

@@ -59,6 +59,25 @@ class FileTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(filesize($this->file->getPath()), $this->file->size());
     }
 
+    public function testMove()
+    {
+        $path = __DIR__.'/Fixtures/test.copy.gif';
+        $targetPath = __DIR__.'/Fixtures/test.target.gif';
+        @unlink($path);
+        @unlink($targetPath);
+        copy(__DIR__.'/Fixtures/test.gif', $path);
+
+        $file = new File($path);
+        $file->move($targetPath);
+
+        $this->assertTrue(file_exists($targetPath));
+        $this->assertFalse(file_exists($path));
+        $this->assertEquals($targetPath, $file->getPath());
+
+        @unlink($path);
+        @unlink($targetPath);
+    }
+
     protected function createMockGuesser($path, $mimeType)
     {
         $guesser = $this->getMock('Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface');