Ejemplo n.º 1
0
 function save()
 {
     $errorMessage = $this->validate();
     if ($errorMessage) {
         return false;
     }
     $formFieldName = $this->formFieldName;
     if (!$this->fileName) {
         do {
             // select new random name
             $imgSrc = substr(md5(rand()), 0, 8) . "." . $this->fileExtension;
         } while (file_exists($this->savePath . $imgSrc));
         // while this name is already busy
         $this->fileName = $imgSrc;
     }
     if ($this->autoCreateDirs) {
         $this->savePath = UploadedFile::createDirsToFile($this->savePath, $this->fileName);
     }
     if (move_uploaded_file($_FILES[$formFieldName]['tmp_name'], $this->savePath . $this->fileName)) {
         return true;
     }
     return false;
 }