Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * Test get extension
  */
 public function testGetExtension()
 {
     $result = $this->httpFile->getExtension();
     $this->assertEquals('jpeg', $result);
 }