之前进行了管理界面通过行政办公查看工作日志的附件BUG修正,但是后来发现个人页面的附近也是不正常的。经过检查inc/attach.php文件发现是路径的问题,但是路径在配置文件里改成绝对后,管理页面附件又异常了(有可能是文件引用编码不一致导致的)。由于问题急需解决,所以后来考虑直接判定一下来源,如果是个人的则修改下路径并转码,如果是管理页面的则用默认的路径。
修改后的文件代码如下:

<?php
/*********************/
/* */
/* Version : 5.1.0 */
/* Author : RM */
/* Comment : 071223 */
/* */
/*********************/
include_once( "inc/auth.php" );
include_once( "inc/utility_file.php" );
$DIRECT_VIEW=$_GET["DIRECT_VIEW"];
$FB_STR1 = urldecode( $ATTACHMENT_NAME );
if ( stristr( $MODULE, "/" ) || stristr( $MODULE, "\\" ) || stristr( $YM, "/" ) || stristr( $YM, "\\" ) || stristr( $ATTACHMENT_ID, "/" ) || stristr( $ATTACHMENT_ID, "\\" ) || stristr( $FB_STR1, "/" ) || stristr( $FB_STR1, "\\" ) )
{
message( "错误", "参数含有非法字符。" );
exit( );
}
$ATTACHMENT_ID_OLD = $ATTACHMENT_ID;
$ATTACHMENT_ID = attach_id_decode( $ATTACHMENT_ID, $ATTACHMENT_NAME );
$MYOA_ATTACHMENT_NAME = $ATTACHMENT_NAME;
if ( $MODULE != "" && $YM != "" )
{
$URL = $ATTACH_PATH2.$MODULE."/".$YM."/".$ATTACHMENT_ID.".".$ATTACHMENT_NAME;
}
else
{
$URL = $ATTACH_PATH.$ATTACHMENT_ID."/".$ATTACHMENT_NAME;
}
//时鹏亮2013.6.18解决附件无法查找中文提示找不到文件
$fromurl=$_SERVER["HTTP_REFERER"];
if(!strpos($fromurl,'/general/diary/edit.php')){
$ATTACH_PATH2="../attach/";
$URL = $ATTACH_PATH2.$MODULE."/".$YM."/".$ATTACHMENT_ID.".".$ATTACHMENT_NAME;
$URL=iconv('EUC-CN','UTF-8',$URL);
}
//以上内容为个人添加内容
if ( !file_exists( $URL ) )
{
if ( $MODULE == "" && $YM == "" )
{
$ATTACHMENT_ID = ( $ATTACHMENT_ID_OLD - 2 ) / 3;
$URL = $ATTACH_PATH.$ATTACHMENT_ID."/".$ATTACHMENT_NAME;
if ( !file_exists( $URL ) )
{
echo "文件名:".$MYOA_ATTACHMENT_NAME."<br>抱歉,您所访问的文件不存在,可能已经被删除或转移,请联系OA管理员。<br>error code:1";
button_back( );
exit( );
}
}
else
{
echo "文件名:".$MYOA_ATTACHMENT_NAME."<br>抱歉,您所访问的文件不存在,可能已经被删除或转移,请联系OA管理员。$URL<br>";
button_back( );
exit( );
}
}
$file_ext = strtolower( substr( $MYOA_ATTACHMENT_NAME, strpos( $MYOA_ATTACHMENT_NAME, "." ) ) );
if ( is_office( $FB_STR1 ) )
{
oc_log( trim( $YM."_".$ATTACHMENT_ID, "_" ), $FB_STR1, 3 );
}
switch ( $file_ext )
{
case ".jpg" :
case ".jpeg" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "image/jpeg";
$img_info = getimagesize( $URL );
if ( !( $img_info['channels'] == 4 ) && !( 0 < stripos( $_SERVER['HTTP_USER_AGENT'], "MSIE 6.0" ) ) || !( 0 < stripos( $_SERVER['HTTP_USER_AGENT'], "MSIE 7.0" ) ) || !( 0 < stripos( $_SERVER['HTTP_USER_AGENT'], "MSIE 8.0" ) ) )
{
break;
}
$CMYK = TRUE;
break;
case ".bmp" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "image/bmp";
break;
case ".gif" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "image/gif";
break;
case ".jpg" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "image/png";
break;
case ".html" :
case ".htm" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "text/html";
break;
case ".wmv" :
case ".wav" :
case ".mid" :
case ".mht" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "application/octet-stream";
break;
case ".pdf" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "application/pdf";
break;
case ".swf" :
if($DIRECT_VIEW==1){$COTENT_TYPE = 0;}else{$COTENT_TYPE = 1;}//时鹏亮2013.6.14添加检测是否预览
$COTENT_TYPE_DESC = "application/x-shockwave-Flash";
break;
$COTENT_TYPE = 1;
$COTENT_TYPE_DESC = "application/octet-stream";
case ".doc" :
case ".dot" :
$COTENT_TYPE = $ATTACH_OFFICE_OPEN_IN_IE ? 0 : 1;
$COTENT_TYPE_DESC = $ATTACH_OFFICE_OPEN_IN_IE ? "application/msword" : "application/octet-stream";
break;
case ".xls" :
case ".xlc" :
case ".xll" :
case ".xlm" :
case ".xlw" :
case ".csv" :
$COTENT_TYPE = $ATTACH_OFFICE_OPEN_IN_IE ? 0 : 1;
$COTENT_TYPE_DESC = $ATTACH_OFFICE_OPEN_IN_IE ? "application/msExcel" : "application/octet-stream";
break;
case ".ppt" :
case ".pot" :
case ".pps" :
case ".ppz" :
$COTENT_TYPE = $ATTACH_OFFICE_OPEN_IN_IE ? 0 : 1;
$COTENT_TYPE_DESC = $ATTACH_OFFICE_OPEN_IN_IE ? "application/mspowerpoint" : "application/octet-stream";
break;
case ".docx" :
case ".dotx" :
case ".xlsx" :
case ".xltx" :
case ".pptx" :
case ".potx" :
case ".ppsx" :
$COTENT_TYPE = $ATTACH_OFFICE_OPEN_IN_IE ? 0 : 1;
$COTENT_TYPE_DESC = $ATTACH_OFFICE_OPEN_IN_IE ? "application/vnd.openxmlformats" : "application/octet-stream";
break;
case ".rm" :
case ".rmvb" :
$COTENT_TYPE = 1;
$COTENT_TYPE_DESC = "audio/x-pn-realaudio";
break;
$COTENT_TYPE = 1;
$COTENT_TYPE_DESC = "application/octet-stream";
}
/*echo "此图片为CMYK色彩模式,您当前浏览器不支持此格式图片显示,请转换为RGB模式。";
button_back( );
exit( );*/
ob_end_clean( );
header( "Cache-control: private" );
header( "Content-type: ".$COTENT_TYPE_DESC );
header( "Accept-Ranges: bytes" );
header( "Content-Length: ".sprintf( "%u", filesize( $URL ) ) );
if ( stristr( $HTTP_USER_AGENT, "MSIE" ) && $ATTACH_UTF8 )
{
$MYOA_ATTACHMENT_NAME = urlencode( iconv( ini_get( "default_charset" ), "utf-8", $MYOA_ATTACHMENT_NAME ) );
}
if ( $COTENT_TYPE == 1 )
{
header( "Content-Disposition: attachment; filename=\"".$MYOA_ATTACHMENT_NAME."\"" );
}
else
{
header( "Content-Disposition: filename=\"".$MYOA_ATTACHMENT_NAME."\"" );
}
$handle = fopen( $URL, "rb" );
$contents = "";
while ( !feof( $handle ) )
{
echo $contents = fread( $handle, 8192 );
}
fclose( $handle );
?>

OA配置文件附件路径部分代码如下:

$ATTACH_PATH2="/www/oa.xxx.cn/attach/";

PS:懂行的人一看就知道我改的部分完全是半吊子的改法~希望如果技术大牛有更好的解决办法可以提出来让我学习一下共同进步。谢谢。

Related Posts: 通达office anywhere2010-windows迁移Nginx后用户界面无法上传附件解决过程 :