function getTxtAttachByMd5($message, $filename_title, $ext) { global $_G; $filename = date('His') . '' . strtolower(random(16)); //$ext=strtolower(substr(strrchr($filename_title, '.'), 1, 10)); if (!$ext) { $ext = 'dzzdoc'; } if ($ext && in_array($ext, $_G['setting']['unRunExts'])) { $unrun = 1; } else { $unrun = 0; } //保存附件并且生成附件MD5; $subdir = $subdir1 = $subdir2 = ''; $subdir1 = date('Ym'); $subdir2 = date('d'); $subdir = $subdir1 . '/' . $subdir2 . '/'; $target1 = 'dzz/' . $subdir . 'index.html'; $target = 'dzz/' . $subdir; $target_attach = $_G['setting']['attachdir'] . $target1; $targetpath = dirname($target_attach); dmkdir($targetpath); if ($message == '') { $message = ' '; } if (!file_put_contents($_G['setting']['attachdir'] . $target . $filename . '.' . ($unrun ? 'dzz' : $ext), $message)) { return false; } $size = @filesize($_G['setting']['attachdir'] . $target . $filename . '.' . ($unrun ? 'dzz' : $ext)); $md5 = md5_file($_G['setting']['attachdir'] . $target . $filename . '.' . ($unrun ? 'dzz' : $ext)); if ($md5 && ($attach = C::t('attachment')->fetch_by_md5($md5))) { $attach['filename'] = $filename_title; $attach['filetype'] = strtolower($ext); @unlink($_G['setting']['attachdir'] . $target . $filename . '.' . ($unrun ? 'dzz' : $ext)); } else { $remote = 0; $attach = array('filesize' => $size, 'attachment' => $target . $filename . '.' . ($unrun ? 'dzz' : $ext), 'filetype' => strtolower($ext), 'filename' => $filename_title, 'remote' => $remote, 'copys' => 0, 'md5' => $md5, 'unrun' => $unrun, 'dateline' => $_G['timestamp']); if (!($attach['aid'] = DB::insert('attachment', $attach, 1))) { return false; } try { if ($remoteid = io_remote::MoveToSpace($attach)) { $attach['remote'] = $remoteid; C::t('attachment')->update($attach['aid'], array('remote' => $remoteid)); @unlink($_G['setting']['attachdir'] . $target . $filename . '.' . ($unrun ? 'dzz' : $ext)); } } catch (Exception $e) { //return array('error'=>$e->getMessage()); return false; } } return $attach; }