コード例 #1
0
 public function import_to_oss($file_path)
 {
     if (!$this->startsWith($file_path, $this->www_root)) {
         return;
     }
     if (!file_exists($file_path)) {
         print "{$file_path} does not exist. \n";
         return;
     }
     $from_pos = strlen($this->www_root);
     $object_name = substr($file_path, $from_pos + 1);
     $param = array("file_root" => $this->www_root, "file_path" => $object_name);
     $web_file = CWebFile::get_url($this->www_root, $object_name);
     if ($web_file == false) {
         //new file;
         $web_file = new CWebFile(array("file_root" => $this->www_root, "file_path" => $object_name));
     } else {
         //old file, update it
         $check_sum = sha1_file($file_path);
         if ($check_sum == $web_file->file_sha1) {
             return;
         }
         //update .
         $st = stat($file_path);
         $web_file->file_ctime = $st['ctime'];
         $web_file->file_mtime = $st['mtime'];
         $web_file->file_atime = $st['atime'];
         $web_file->file_sha1 = $check_sum;
         $web_file->import_time = time();
     }
     try {
         $this->_oss->put_object($file_path, $object_name);
         print "importing {$file_path} => {$object_name} \n";
     } catch (\OSS\Core\OssException $e) {
         printf(__FUNCTION__ . ": FAILED\n");
         printf($e->getMessage() . "\n");
         return;
     }
     $web_file->save();
 }
コード例 #2
0
 public static function get_db_instance()
 {
     if (self::$_dbh == NULL) {
         try {
             $dsn = sprintf("mysql:host=%s;port=%d;dbname=%s", self::DB_HOST, self::DB_PORT, self::DB_NAME);
             self::$_dbh = new PDO($dsn, self::DB_USER, self::DB_PASS);
             self::$_dbh->query("SET NAMES utf");
             return self::$_dbh;
         } catch (PDOException $e) {
             printf(__FUNCTION__ . " cannot connect to mysql :  ");
             printf($e->getMessage() . "\n");
             exit;
         }
     } else {
         return self::$_dbh;
     }
 }