Permalink
Browse files

Merge remote-tracking branch 'origin/master' into develop

  • Loading branch information...
2 parents ce87787 + 27ed746 commit 7dd71daac39af84b51925b58aafff507c01fcc80 @codeguy codeguy committed Apr 15, 2013
Showing with 20 additions and 5 deletions.
  1. +3 −0 composer.json
  2. +6 −2 src/Upload/File.php
  3. +1 −1 src/Upload/Storage/Base.php
  4. +10 −2 src/Upload/Storage/FileSystem.php
View
@@ -16,6 +16,9 @@
"php": ">=5.3.0",
"mikey179/vfsStream": "*"
},
+ "require-dev": {
+ "phpunit/phpunit": "3.7.*"
+ },
"autoload": {
"psr-0": { "Upload": "src" }
}
View
@@ -292,16 +292,20 @@ public function addError($error)
/**
* Upload file (delegated to storage object)
+ * @param string $newName Give the file it a new name
* @return bool
* @throws \Upload\Exception\UploadException If file does not validate
*/
- public function upload()
+ public function upload($newName = null)
{
if ($this->validate() === false) {
throw new \Upload\Exception\UploadException('File validation failed');
}
- return $this->storage->upload($this);
+ // Update the name, leaving out the extension
+ $this->name = pathinfo($newName, PATHINFO_FILENAME);
+
+ return $this->storage->upload($this, $newName);
}
/********************************************************************************
@@ -41,5 +41,5 @@
*/
abstract class Base
{
- abstract public function upload(\Upload\File $file);
+ abstract public function upload(\Upload\File $file, $newName = null);
}
@@ -75,12 +75,20 @@ public function __construct($directory, $overwrite = false)
/**
* Upload
* @param \Upload\File $file The file object to upload
+ * @param string $newName Give the file it a new name
* @return bool
* @throws \RuntimeException If overwrite is false and file already exists
*/
- public function upload(\Upload\File $file)
+ public function upload(\Upload\File $file, $newName = null)
{
- $newFile = $this->directory . $file->getNameWithExtension();
+ if (is_string($newName)) {
+ $fileName = strpos($newName, '.') ? $newName : $newName.'.'.$file->getExtension();
+
+ } else {
+ $fileName = $file->getNameWithExtension();
+ }
+
+ $newFile = $this->directory . $fileName;
if ($this->overwrite === false && file_exists($newFile)) {
$file->addError('File already exists');
throw new \Upload\Exception\UploadException('File already exists');

0 comments on commit 7dd71da

Please sign in to comment.