关于PHP上传文件名称,如果修改,可以使上传的文件保存原有的文件名!

ligenwin 2012-06-06 12:29:25
上传组件 downfiles.inc.php
<?php
defined('IN_PHPCMS') or exit('Access Denied');

require_once 'attachment.class.php';
session_start();
$attachment = new attachment($mod);
$_SESSION['downfiles'] = 1;
if($dosubmit)
{
if($catid)
{
$C = cache_read('category_'.$catid.'.php');
$upload_allowext = $C['upload_allowext'] ? $C['upload_allowext'] : UPLOAD_ALLOWEXT;
$upload_maxsize = $C['upload_maxsize'] ? $C['upload_maxsize'] : UPLOAD_MAXSIZE;
}
else
{
$upload_allowext = UPLOAD_ALLOWEXT;
$upload_maxsize = UPLOAD_MAXSIZE;
}
$aids = $attachment->upload('uploadfile', $upload_allowext, $upload_maxsize, 1);
if(!$aids)
{
msg($attachment->error(), '', 6000);
exit;
}
$atts = $attachment->uploadedfiles;
$filesize = $attachment->uploadedfiles[0]['filesize'];
$filesize = $attachment->size($filesize);
foreach($atts AS $k=>$v)
{
$name = $file_description[$k+1];
if($name=='')
{
$name = basename($v['filename'],'.'.$v['fileext']);
}
echo '<script>var s = parent.document.getElementById("downurls").value == "" ? "" : "#";var t = parent.document.getElementById("downurls_aid").value == "" ? "" : ",";parent.document.getElementById("downurls").value += s+"'.$name.'|'.$filesize.'|'.UPLOAD_URL.$v['filepath'].'|适用机型:";parent.document.getElementById("downurls_aid").value += t+"'.$aids[$k].'";parent.document.getElementById("filesize").value="'.$v['filesize'].'";</script>';
}
echo '<script>parent.document.getElementById("filesize").value="'.$filesize.'";</script>';
msg('上传成功', '', 3000);
}
else
{
include admin_tpl('downfiles');
}

function msg($msg, $forward = '', $timeout = 2000)
{
if(!$forward)
{
global $forward;
}
echo '<table width="100%" cellpadding="0" cellspacing="0" height="100%" bgcolor="#F1F3F5">';
echo '<tr><td style="font-size:12px;color:blue;">';
echo '<a href="'.$forward.'">'.$msg.' Click To Back</a>';
echo '</td></tr></table>';
echo '<script>setTimeout("window.location=\''.$forward.'\'", '.$timeout.');</script>';
exit;
}
?>


如何修改,可以使上传的文件保存原有的文件名! 这段代码我确实没看明白! 谢谢各位大侠!
下面1楼是上传文件引用文件'attachment.class.php'
...全文
104 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ligenwin 2012-06-06
  • 打赏
  • 举报
回复
上传组件引用文件
<?php
defined('IN_PHPCMS') or exit('Access Denied');

require_once 'attachment.class.php';
session_start();
$attachment = new attachment($mod);
$_SESSION['downfiles'] = 1;
if($dosubmit)
{
if($catid)
{
$C = cache_read('category_'.$catid.'.php');
$upload_allowext = $C['upload_allowext'] ? $C['upload_allowext'] : UPLOAD_ALLOWEXT;
$upload_maxsize = $C['upload_maxsize'] ? $C['upload_maxsize'] : UPLOAD_MAXSIZE;
}
else
{
$upload_allowext = UPLOAD_ALLOWEXT;
$upload_maxsize = UPLOAD_MAXSIZE;
}
$aids = $attachment->upload('uploadfile', $upload_allowext, $upload_maxsize, 1);
if(!$aids)
{
msg($attachment->error(), '', 6000);
exit;
}
$atts = $attachment->uploadedfiles;
$filesize = $attachment->uploadedfiles[0]['filesize'];
$filesize = $attachment->size($filesize);
foreach($atts AS $k=>$v)
{
$name = $file_description[$k+1];
if($name=='')
{
$name = basename($v['filename'],'.'.$v['fileext']);
}
echo '<script>var s = parent.document.getElementById("downurls").value == "" ? "" : "#";var t = parent.document.getElementById("downurls_aid").value == "" ? "" : ",";parent.document.getElementById("downurls").value += s+"'.$name.'|'.$filesize.'|'.UPLOAD_URL.$v['filepath'].'|适用机型:";parent.document.getElementById("downurls_aid").value += t+"'.$aids[$k].'";parent.document.getElementById("filesize").value="'.$v['filesize'].'";</script>';
}
echo '<script>parent.document.getElementById("filesize").value="'.$filesize.'";</script>';
msg('上传成功', '', 3000);
}
else
{
include admin_tpl('downfiles');
}

function msg($msg, $forward = '', $timeout = 2000)
{
if(!$forward)
{
global $forward;
}
echo '<table width="100%" cellpadding="0" cellspacing="0" height="100%" bgcolor="#F1F3F5">';
echo '<tr><td style="font-size:12px;color:blue;">';
echo '<a href="'.$forward.'">'.$msg.' Click To Back</a>';
echo '</td></tr></table>';
echo '<script>setTimeout("window.location=\''.$forward.'\'", '.$timeout.');</script>';
exit;
}
?>

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧