예제 #1
0
 /**
  * @throws \Bluz\Request\RequestException
  */
 public function renameFileName()
 {
     $fileName = strtolower($this->file->getName());
     // Prepare filename
     $fileName = preg_replace('/[ _;:]+/i', '-', $fileName);
     $fileName = preg_replace('/[-]+/i', '-', $fileName);
     $fileName = preg_replace('/[^a-z0-9.-]+/i', '', $fileName);
     // If name is wrong
     if (empty($fileName)) {
         $fileName = date('Y-m-d-His');
     }
     // If file already exists, increment name
     $originFileName = $fileName;
     $counter = 0;
     while (file_exists($this->uploadPath . $fileName . '.' . $this->file->getExtension())) {
         $counter++;
         $fileName = $originFileName . '-' . $counter;
     }
     // Setup new name and move to user directory
     $this->file->setName($fileName);
     $this->file->moveTo($this->uploadPath);
 }
예제 #2
0
 /**
  * Test get name
  */
 public function testGetName()
 {
     $result = $this->httpFile->getName();
     $this->assertEquals('test', $result);
 }