public function run($title, $ext, $path, $flag = 0) { $this->_preRet = array(); $this->_rand = time() . '_' . rand(100, 200); $this->_errno = 0; $this->_errmsg = ''; $this->_oriRet = array(); $this->_flag = $flag; //Plat_Log::addNotice('rand', $this->_rand); //Plat_Log::debug('rand:'.$this->_rand); //Plat_Log::addNotice('title', $title); Plat_Log::debug('title:' . $title); if (!is_file($path)) { $this->_errno = 404; $this->_errmsg = 'file not found:' . $title; Plat_Log::fatal($this->_errmsg, $this->_errno); return false; } $doc_md5 = md5_file($path); $size = filesize($path); //Plat_Log::addNotice('size', $size); //Plat_Log::addNotice('doc_md5', $doc_md5); //Plat_Log::debug('size:'.$size); //Plat_Log::debug('doc_md5:'.$doc_md5); $ret = $this->preUpload($title, $ext, $doc_md5, $size); if (!$ret) { Plat_Log::debug('preUpload failed'); return false; } $repeat = $this->_preRet['repeat']; if (!$repeat) { $ret = $this->newUpload($title, $ext, $doc_md5, $size, $path); if (!$ret) { return false; } } $ret = $this->complete($title, $ext, $doc_md5, $size); if (!$ret) { return false; } //Plat_Log::addNotice('doc_id', $this->_doc_id); Plat_Log::debug('doc_id:' . $this->_doc_id); //Plat_Log::notice('upload success', 0); //Plat_Log::debug('upload success'); return $this->_doc_id; }
$path = urldecode($argv[1]); $title = urldecode($argv[2]); $file_name_arr = explode(".", $path); $ext = array_pop($file_name_arr); if (!mb_check_encoding($title, 'UTF-8')) { $title = mb_convert_encoding($title, 'UTF-8', 'GBK'); } if (empty($title) || empty($ext)) { Plat_Log::fatal('empty title or ext in:' . $file); exit(0); } $min = date('i'); $date_tail = intval($min / GAP) * GAP; $log_name = sprintf('%s%s%02d%s', 'upload', date("YmdH"), $date_tail, '.log'); Plat_Log::setOdp(false); Plat_Log::setLogPath(LOG_PATH . $log_name); $upload = new Plat_Upload($cookie); for ($i = 0; $i < 2; $i++) { $doc_id = $upload->run($title, $ext, $path, $flag); if (!empty($doc_id)) { break; } } if (empty($doc_id)) { Plat_Log::debug("path:" . $argv[1] . ":file:" . $argv[2]); exit(0); } else { echo $doc_id . "\n"; Plat_Log::addNotice('uploaded doc_id', $doc_id); } exit(0);
// 获取上传文档的页数 $file_page = intval($doc_info['page']); // 获取文件后缀 $ext = $doc_info['type']; $type = getTypeByExt($ext); if (empty($type)) { Plat_Log::fatal('get type error'); exit(0); } // 获取文件大小 $size = $doc_info['size']; // 获取文件标题 $title = $doc_info['title']; // 获取默认文档分类 $auto_class = $upload->getAutoClass($doc_id, $title, $size, $type); Plat_Log::debug('auto class:' . json_encode($auto_class)); for ($i = 0; $i < 2; $i++) { // 验证分类 if (autoClassOk($auto_class)) { break; } sleep($i * 1); $auto_class = $upload->getAutoClass($doc_id, $title, $size, $type); } if (!autoClassOk($auto_class)) { Plat_Log::fatal('get cid error:' . json_encode($auto_class)); exit(0); } $cid1 = $auto_class['cid1']; $cid2 = $auto_class['cid2']; $cid3 = $auto_class['cid3'];