Esempio n. 1
0
 public function move($newFileName = null)
 {
     if ($this->field) {
         if (!isset($_FILES[$this->field]['name'])) {
             throw new Exception("File field {$this->field}: name is empty");
         }
         if ($err = $_FILES[$this->field]['error']) {
             throw new Exception("File field {$this->field} error: {$err}");
         }
         /* process with $_FILES */
         // $_FILES['upload']['tmp_name'];
         $filename = $newFileName ? $newFileName : $_FILES[$this->field]['name'];
         $path = $this->uploadDir . DIRECTORY_SEPARATOR . $filename;
         $path = FileUtils::filename_increase($path);
         if (move_uploaded_file($_FILES['upload']['tmp_name'], $path) === false) {
             return false;
         }
         return $path;
     } else {
         $content = $this->getContent();
         $filename = $newFileName ? $newFileName : $this->getFileName();
         $path = $this->uploadDir . DIRECTORY_SEPARATOR . $filename;
         $path = FileUtils::filename_increase($path);
         if (file_put_contents($path, $content) === false) {
             return false;
         }
         return $path;
     }
 }