| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:图片上传问题求解,谢谢!
只看楼主 加入收藏
znmw
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-3-6
收藏
 问题点数:0 回复次数:0 
图片上传问题求解,谢谢!
我要使每编文章上传的多个图片都在使用每编文章的ID做为文件夹(也就是说每编文章的图片都不相同文件夹),请问怎么修改以下代码?谢谢!
代码如下:
<!--#include file="../Inc/conn.asp"-->
<!--#include file="admin_check.asp"-->
<!--#include file="../Inc/UploadClass.asp"-->
<%
Dim1 new138,Up_Max,Action
Up_Max=10
Action=Lcase(Trim(Request("Action")))
new138_upfiletype="jpg|gif"
Select Case Action
    Case "add":Save_Upfile
    Case Else:Main
End Select
Sub Save_Upfile
    Dim i,Filename,formPath,Err_Link,File_Type
    Echo "<html>"
    Echo "<style type=""text/css""> "
    Echo "*{margin:0;padding:0;font-size:12px;background:#E7ECF6;}"
    Echo "</style>"
    Echo "<body>"
    Dim sUploadDir:sUploadDir=SitePath&SiteUp&"/photo/" & Year(Now) & right("0" & Month(Now), 2) &"/"怎么在这里添加新建文章的ID代码?谢谢!
    CreateFolder(sUploadDir)
    Set new138=New UpLoadClass
        new138.FileType=new138_upfiletype
        new138.SavePath=sUploadDir
        new138.MaxSize=999999
        new138.AutoSave=0
        new138.Open()
        For I=2 to Ubound(new138.FileItem)
            Filename=new138.SavePath&new138.Form(new138.FileItem(I))
            Err_Link="<a href=""Admin_FileUp.asp"">重新上传</a>"
            Select Case new138.Form(new138.FileItem(I)&"_Err")
                Case -1:Echo"没有文件上传,"&Err_Link:Died
                Case 1: Echo"文件过大,上传失败,"&Err_Link:Died
                Case 2: Echo"不允许被上传的文件,"&Err_Link:Died
                Case 3: Echo"文件过大,且不允许被上传而未被保存,"&Err_Link:Died
                Case 4:    Echo"文件保存失败,"&Err_Link:Died
            End Select
            
            Select Case Lcase(Right(Filename,3))
                Case "flv":File_Type=0
                Case Else:File_Type=1
            End Select
                Echo "<script>parent.KE.insertHtml('Content','"
                Select Case File_Type
                Case 0:Echo "[flv=480,360]"&Filename&"[/flv]<br>"
                Case Else:Echo "附件下载:<a href="""&Filename&""" Target=""_blank"">"&new138.Form(new138.FileItem(I))
&"</a><br>"
                End Select
                Echo "');</script>"
        Next
        IF Len(Filename)=0 Then
            Echo "<a href=""Admin_FileUp.asp"">请先添加附件</a>"
        Else
            Echo "文件上传成功,<a href=""Admin_FileUp.asp"">继续上传</a>"
        End IF
    Set new138=Nothing
End Sub
Sub Main
%>
<html>
<head>
<title>new138多文件上传</title>
<script type="text/javascript">
function MultiSelector(list_target, max)
{
this.list_target = list_target;
this.count = 0;
this.id = 0;
var o=parent.document.getElementById("UpLoadIframe");
if (max){this.max = max;}else{this.max = -1;}
this.addElement = function(element)
{
if (element.tagName == 'INPUT' && element.type == 'file')
{
element.name = 'file_' + this.id++;
element.multi_selector = this;
element.onchange = function()
{
var inputs = document.getElementsByTagName("input");
var count = 0;
var total=inputs.length;
for(var i=0;i <inputs.length;i++)
{
if (inputs[i].type == 'file')
{
if(this.value==inputs[i].value)
{
count++;
}
}
}
if(count>1)
{
alert("该文件已存在!");
return false;
}
if(!this.value.IsPicture())
{
alert("不允许上传此类文件!允许的类型:<%=new138_upfiletype%>");
return false;
}

var new_element=document.createElement('input');
new_element.type='file';
new_element.size=1;
new_element.className="addfile";
this.parentNode.insertBefore(new_element, this);
this.multi_selector.addElement(new_element);
this.multi_selector.addListRow(this);
this.style.position ='absolute';
this.style.left='0px';
}
if (this.max != -1 && this.count >= this.max-1)
{
element.disabled = true;
}
this.count++;
this.current_element = element;
(o.style||o).height=(parseInt(this.count)*16)+'px';
}
else
{
alert('Error: not a file input element');
}
}
this.addListRow = function(element)
{
var new_row = document.createElement('div');
new_row.className="divName";
var a = document.createElement("a"); a.title = "删除";a.innerHTML = "删除"; a.href = "javascript:void(0);";
new_row.element = element;
a.onclick = function()
{
this.parentNode.element.parentNode.removeChild(this.parentNode.element);
this.parentNode.parentNode.removeChild(this.parentNode);
this.parentNode.element.multi_selector.count--;
(o.style||o).height=(parseInt(this.parentNode.element.multi_selector.count)*16)+'px';
this.parentNode.element.multi_selector.current_element.disabled = false;

return false;
}
var filename = element.value.substring(element.value.lastIndexOf("\\")+1)+" ";
new_row.innerHTML = filename;
new_row.appendChild(a);
this.list_target.appendChild(new_row);
}
}
String.prototype.IsPicture = function()
{
<%
Dim jstype,js_type,i
jstype=""
js_type=Split(new138_upfiletype,"|")
For i=0 to ubound(js_type)
jstype=jstype&"."&Lcase(js_type(i))&"|"
Next
%>
var strFilter="<%=jstype%>" ;
if(this.indexOf(".")>-1)
{
    var p = this.lastIndexOf(".");
    var strPostfix=this.substring(p,this.length) + '|';
    strPostfix = strPostfix.toLowerCase();
    if(strFilter.indexOf(strPostfix)>-1)
    {
        return true;
    }
}
return false;
}
</script>

<style type="text/css">
*,body,form{margin:0;padding:0;font-size:12px;background:#E7ECF6;}
a:link,a:visited{color:#00F;}
a.addfile{display:block;float:left;height:20px;margin-top:-1px;position:relative;text-decoration:none;top:0pt;width:80px;cursor:pointer;}
a:hover.addfile{display:block;float:left;height:20px;margin-top:-1px;position:relative;text-
decoration:none;top:0pt;width:80px;cursor:pointer;}
input.addfile{cursor:pointer;height:20px;position:absolute;margin:0px 0 0 -75px;width:1px;filter:alpha(opacity=0);opacity:0;}
.bnt{background:#fff;border:0;text-decoration:underline;color:#00f;}
#files_list div{clear:both;margin-top:2px;}
.divName{float:left;padding-left:5px;}
form span{color:#999;}
.input{position:absolute;margin:-4px 0 0 0;}
</style>
</head>
<body>
<form id="form1" method="post" action="?Action=add" enctype="multipart/form-data">
<a href="javascript:void(0);" title="点击添加附件,支持类型:<%=new138_upfiletype%>">添加<input id="my_file_element"  class="addfile" size="1"  
type="file" hideFocus /></a> <a href="javascript:form1.submit()">上传</a> 一次最多上传<%=Up_Max%>个<span id="files_list"></span>
<script type="text/javascript">
var multi_selector = new MultiSelector(document.getElementById('files_list'),<%=Up_Max+1%>);
multi_selector.addElement(document.getElementById('my_file_element'));
</script>
</form>
<%End Sub%>
</body>
</html>
搜索更多相关主题的帖子: file include Request 文章 图片 
2012-03-06 20:05
快速回复:图片上传问题求解,谢谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014264 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved