コード例 #1
0
 private function generateTempFile()
 {
     $tempfile = new TempFile($this->getStorage());
     $file = new File($this->getStorage());
     $file->setExportFilename("vpanel-chart-" . date("Y-m-d"));
     $file->save();
     $tempfile->setFile($file);
     $tempfile->setTimestamp(time());
     $tempfile->setUserID($this->getUserID());
     $tempfile->save();
     $this->tempfileids[] = $tempfile->getTempFileID();
     return $tempfile;
 }
コード例 #2
0
ファイル: TempFile.php プロジェクト: dsyman2/X2CRM
 public static function createTempFile($name)
 {
     // delete old temp files if they exist
     $old = time() - 86400;
     // 1 day old
     $oldTempFiles = TempFile::model()->findAll("createDate < {$old}");
     foreach ($oldTempFiles as $oldTempFile) {
         $oldFolder = $oldTempFile->folder;
         $oldName = $oldTempFile->name;
         if (file_exists('uploads/protected/media/temp/' . $oldFolder . '/' . $oldName)) {
             unlink('uploads/protected/media/temp/' . $oldFolder . '/' . $oldName);
         }
         // delete file
         if (file_exists('uploads/protected/media/temp/' . $oldFolder)) {
             rmdir('uploads/protected/media/temp/' . $oldFolder);
         }
         // delete folder
         $oldTempFile->delete();
         // delete database entry tracking temp file
     }
     // generate temp folder name
     $folder = substr(md5(rand()), 0, 10);
     // try to create temp folder
     if (!@mkdir('uploads/protected/media/temp/' . $folder, 0777, true)) {
         return false;
     }
     // couldn't create temp folder
     $tempFile = new TempFile();
     // track temp file in database
     $tempFile->folder = $folder;
     $tempFile->name = $name;
     $tempFile->createDate = time();
     if ($tempFile->save()) {
         return $tempFile;
     } else {
         return false;
     }
 }