求aspx上传文件代码
#region 上传文件的代码
string filerealname = ““; //上传的文件绝对路径
string fileMapPath = ““;//文件在硬盘中实际存储路径
string newFileName = ““;//
if (this.Up_file.PostedFile.ContentLength 》 0)
{
if (Up_file.PostedFile.ContentLength 《 1024 * 1024 * 100)
{
try
{
filerealname = Up_file.PostedFile.FileName;//上传的文件绝对路径
string fileName = filerealname.Substring(filerealname.LastIndexOf(@“\“) + 1);//取得文件扩展名
newFileName = DateTime.Now.ToString(“yyyyMMddHHmmss“) + “_“ + fileName;//自动根据日期为文件命名,确保文件名不重复
string fullpath = Server.MapPath(“~/Notice/upload/“);//文件的上传路径
if (!Directory.Exists(fullpath))//没有找到路径,创建新文件夹
{
Directory.CreateDirectory(fullpath);//创建一个文件夹
}
fileMapPath = Server.MapPath(“~/Notice/upload/“ + newFileName);//上传文件到服务器
Up_file.PostedFile.SaveAs(fileMapPath);
//保存文件路径
values += “upload/“ + newFileName + “’,’“;
}
catch (Exception)
{
//上传超限提示
Page.ClientScript.RegisterStartupScript(this.GetType(), ““, “showMsg(’#Up_file’, ’#imgTishi4’, ’文件上传出错!’);“, true);
return;
}
}
else
{
//上传超限提示
Page.ClientScript.RegisterStartupScript(this.GetType(), ““, “showMsg(’#Up_file’, ’#imgTishi4’, ’文件超出100M,请重新选择文件!’);“, true);
return;
}
}
else
values += “无’,’“;
#endregion
asp上传文件到服务器的代码怎么写
《html》
《head》
《meta http-equiv=“Content-Type“ content=“text/html; charset=gb2312“》
《title》无标题文档《/title》
《/head》
《body》
《%
’On Error Resume Next
Response.Expires=0
if Request.TotalBytes then
set a=createobject(“adodb.stream“)
a.Type=1
a.Open
a.write Request.BinaryRead(Request.TotalBytes)
a.Position=0
b=a.Read
c=chrB(13)&chrB(10)
d=clng(instrb(b,c))
e=instrb(d+1,b,c)
set f=createobject(“adodb.stream“)
f.type=1
f.open
a.Position=d+1
a.copyto f,e-d-3
f.Position=0
f.type=2
f.CharSet=“GB2312“
g=f.readtext
f.Close
h=mid(g,instrRev(g,“\“)+1,e)
i=instrb(b,c&c)+4
j=instrb(i+1,b,leftB(b,d-1))-i-2
if j 《1 then
set f =nothing
set a =nothing
response.write “未选择要上传的文件《a href=’?’》重新上传《/a》“
response.end
end if
f.Type=1
f.Open
a.Position=i-1
a.CopyTo f,j
h = Mid(h, InStrRev(h, “filename=“““) + 10) ’这是我帮你添加的,文件名的获取没有正确
f.SaveToFile server.mappath(“/EXCEL/“& h),2
f.Close
set f=Nothing
a.Close
set a=Nothing
’response.write “《a href=“&Server.URlEncode(h)&“》“&h&“《/a》“
end if
If Err.number《》 0 Then
response.Write err.number
response.Write err.Description
Response.End
End If
%》
《script language=“javascript“》
function checkupload() {
if (document.upload_form.fe.value == ““) {
alert(“未选择要上传的文件“);
return false;
}
}
《/script》
《form name=“upload_form“ enctype=“multipart/form-data“ method=“post“ onsubmit=“return(checkupload())“》
《input type=“file“ name=“fe“/》
《input type=“submit“ value=“上传“ name=“B1“/》
《/form》
《/body》
《/html》
求PHP网页上传文件代码.
自定义文件上传函数
:
《?php
/**
* 文件上传
*/
/**
* 文件上传函数
* @param $name string 表单上传框的name值
* @param $file_arr array 上传文件的类型限制
*@param $filesize int 上传文件限制其大小
* @param $path string 文件的保存路径
* @return string 成功返回 “上传成功及文件名“
*/
function uploads($name,$file_arr=array(’jpg’,’png’,’gif’,’JPG’,’GIF’,’PNG’),$filesize=3145728,$path=’uploads’){
//1、检测文件的错误信息,如果是0 就允许上传(保存)
$err=$_FILES;
if($err》0){
if($err==1){
return ’上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。’;
}elseif($err==2){
return ’上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。 ’;
}elseif($err==3){
return ’文件只有部分被上传。’;
}elseif($err==4){
return’没有文件上传’;
}elseif($err》=5){
return ’其他错误’;
}
}
//2、检测文件的类型,是否是我们需要的(png、gif、jpg)
$pre=pathinfo($_FILES,PATHINFO_EXTENSION);
if(!in_array($pre,$file_arr)){
return ’上传的文件类型不符’;
}
//3、检测文件大小
if($_FILES》$filesize){
return ’上传的文件太大’;
}
//4、保存文件
$file_name=date(’YmdHis’,time()).mt_rand(1000,9999).’.’.$pre;
if(is_uploaded_file($_FILES)){
move_uploaded_file($_FILES, $path.“/“.$file_name);
return ’上传成功|’.$file_name;
}else{
return “文件上传失败!“;
}
}
?》
php多文件上传实现代码
这篇文章主要介绍了php多文件上传实现代码,需要的朋友可以参考下
index_uploads.php
代码如下:
《html》
《head》
《meta
charset=“utf-8“》
《title》index_uploads《/title》
《/head》
《body》
《form
action=“uploads.php“
method=“post“
enctype=“multipart/form-data“》
《input
type=“file“
name=“file“》
《br》
《input
type=“file“
name=“file“》
《br》
《input
type=“submit“
value=“uploads“》
《/form》
《/body》
《/html》
uploads.php
代码如下:
《?php
header(“content-type:text/html;charset=utf-8“);
echo
“《pre》“;
print_r($_FILES);
echo
“《/pre》“;
$count
=
count($_FILES);
for
($i
=
0;
$i
《
$count;
$i++)
{
$tmpfile
=
$_FILES;
$filefix
=
array_pop(explode(“.“,
$_FILES));
$dstfile
=
“uploads/files/“.time().“_“.mt_rand().“.“.$filefix;
if
(move_uploaded_file($tmpfile,
$dstfile))
{
echo
“《script》alert(’succeed!’);window.location.href=’index_uploads.php’;《/script》“;
}
else
{
echo
“《script》alert(’fail!’);window.location.href=’index_uploads.php’;《/script》“;
}
}
核心:《1》上传首页中input的name属性是这么设置的。
《2》用while循环上传多文件。
Java中fileupload上传文件的代码
private static DiskFileItemFactory factory;//获得磁盘文件条目工厂
private static ServletFileUpload upload;//文件上传处理类
factory = new DiskFileItemFactory(); //获得磁盘文件条目工厂
factory.setRepository(new File(config.getCache())); //创建缓存工厂
factory.setSizeThreshold(1024*1024*2) ; //设置缓存区的大小
upload = new ServletFileUpload(factory); //高水平的API文件上传处理
upload.setSizeMax(10 * 1024 * 1024);//设置文件上传的最大值
upload.setFileSizeMax(2* 1024 * 1024);//设置文件上传的最大值
List《FileItem》 list = upload.parseRequest(request);
for(FileItem item : list){
String fieldName = item.getFieldName(); //获取表单的属性名字
String fileName = item.getName() ; //获取文件名
if(item.isFormField()){//如果获取的 表单信息是普通的 文本 信息
}else{
File file = new File(“d://test.txt“);
item.write(file);
}
}
php上传文件代码,怎么写
2楼和3楼给你的回答就跟SB一样,自己比你还菜,就瞎扯。我问问题的时候就是被这些SB不停骚扰导致最后无人回答了。
上传代码看这里(带重命名的):
《form action=““ method=“post“ enctype=“multipart/form-data“》
上传文件:《input type=“file“ name=“upLoad“》《br》
重命名为:《input type=“text“ name=“newName“》《br》
《input type=“submit“ name=“submit“》《input type=“reset“ name=“reset“》
《/form》
《br》《i》《small》文件上传到服务器需要一些时间《/small》《/i》《br》
《?php
$upLoadDir=“/“; //为目录变量指定目录位置
$upLoadError=$_FILES;
$fileName=$_FILES;
$fileTemName=$_FILES;
$fileSize=$_FILES;
$newName=$_POST;
function upLoad(){
global $upLoadDir,$upLoadError,$fileName,$fileTemName,$fileSize,$fileSuffix,$newName;
if($newName){ //如果需要被更新文件名
$fileReName=$newName.“.“.pathinfo($fileName,PATHINFO_EXTENSION); //采用新文件名+获取文件名后缀
}else{ //如果不需要更新文件名
$fileReName=$fileName; //定义文件存储位置,并在文件名前加一组随机数字
}
if($upLoadError》0){ //0表示没有错误发生,文件上传成功
echo“错误:“;
switch($upLoadError){
case 1:echo“上传文件超过配置文件规定值。“;break; //1表示上传的文件超过了php.ini中upload_max_filesize选项限制的值
case 2:echo“上传文件超过表单约定值。“;break; //2表示上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值。
case 3:echo“上传文件不完全。“;break; //3表示文件只有部分被上传。
case 4:echo“没有上传文件。“;break; //4表示没有文件被上传。
}
}else{
if(is_uploaded_file($fileTemName)){ //确认文件通过HTTP POST上传
if(!move_uploaded_file($fileTemName,($upLoadDir.$fileReName))){ //如果无法将上传的文件移动到新位置
echo“文件上传失败,请重新上传。“;
}else{ //否则返回成功信息
echo“文件上传成功!《br》“.date(“Y-m-d H:i:s“).“《br》上传文件:“.$fileName.“《br》文件大小:“.number_format(($fileSize/1024/1024),2).“Mb“.“《br》重命名为:“.$fileReName;
}
}else{ //如果不是通过HTTP POST方式上传,则提示非法信息
echo“文件“.$fileName.“不合法!“;
}
}
}
if(!empty($fileName)){
if(is_dir($upLoadDir)){ //如果目录存在
upLoad(); //则执行上传流程
}else{ //如果目录不存在
mkdir($upLoadDir); //则创建目录
upLoad(); //再执行上传流程
}
}else{
echo“请选择需要上传的文件。“;
}
?》
html上传文件代码
在HTML标准中,XMLHttpRequest对象被重新定义,被称为“XMLHttpRequest Level 2”,其中包含了以下5个新特性:
1、支持上传、下载字节流,比如文件、blob以及表单数据。
2、增加了上传、下载中的进度事件。
3、跨域请求的支持。
4、允许发送匿名请求(即不发送HTTP的Referer部分)。
5、允许设置请求的超时。
在这篇教程中,我们主要关注第一和第二项特性,尤其是第二项——它能够提供我们想要的上传进度。和之前的方案不同,这个方案并不要求服务器作出特殊的设置,因此大家边看教程就可以边动手试试了。
上面图示的就是我们能够实现的内容:
1、显示上传的文件信息,比如文件名、类型、尺寸。
2、一个能够显示真实进度的进度条。
3、上传的速度。
4、剩余时间的估算。
5、已上传的数据量。
6、上传结束后服务器返回的响应。
另外,凭借XMLHttpRequest,我们的上传过程整个都是异步的,因此用户在上传文件的时候,依然可以操作网页当中的其它元素,并不需要专门等待上传的完成。而在上传结束后,我们能够获取服务器发回的响应,因此整个上传过程都显得相当顺理成章。
PHP文件上传代码用法
php文件上传代码编写过程
先判断是否上传文件
如果有再来判断上传中是否出错
如果出错 则提示出错信息
如查没出错 再判断文件类型
如果类型符合条件 再判断指定目录中有没有存在该文件
如果没有就把该文件移至指定目录
在php中上传文件必须知道的几个东西
$_FILES 是指被上传文件的名称
$_FILES 是指被上传文件的类型
$_FILES 是指被上传文件的大小 单位为字节(B)
$_FILES 是指被上传文件存在服务器中的临时副本文件名称 文件被移动到指定目录后临文件将被自动消毁
$_FILES 是指由文件上传中有可能出现的错误的状态码 关于各状态含义后在会说明
先来看一下HTML部分
代码如下 复制代码
?《form action=“upload php“ method=“post“ enctype=“multipart/form data“》 上传 《input type=file name=myfile /》 《input type=submit name=submit value=“上传“ /》 《/form》
说明
form标答的action=“upload php“是指点击这个form中的submit的时候 这个上传命令会被发送到这个叫 upload php的页面去处理 method=“post“是指以post方式去送 enctype=“multipart/form data“属性规定了在提交这个表单时要使用哪种内容类型 在表单需要二进制数据时 比如文件内容 请使用“multipart/form data“ 如果要上传文件 这个属性是必要的 input中的type=“file“时 规定了应该把输入作为文件来处理 并且在input后面会有一个浏览的按钮
我们再来看一个PHP处理页面 upload php
代码如下 复制代码
《?php if($_FILES); echo “《script》alert(上传成功!);《/script》“; } } else{ echo “《script》alert(请上传文件!);《/script》“; } ?》
上面超级简单 我们现在来升级一下
upload php
代码如下 复制代码
《!DOCTYPE HTML PUBLIC “ //W C//DTD HTML Transitional//EN“》 《》 《head》 《title》ddd《/title》 《meta equiv=“content type“ content=“text/; charset=UTF “》 《/head》 《body》 《! 文件上传要注意: 要有enctyp method=“post“ 》 《form enctype=“multipart/form data“ action=“uploadProcess php“ method=“post“ 》 《table》 《tr》《td》请填写用户名《/td》《td》《input type=text name=username》《/td》《/tr》 《tr》《td》请简单介绍文件《/td》《td》《textarea rows=“ “ cols=“ “ name=fileintro class=“page_speeder_734321457“》《/textarea》《/td》《/tr》 《tr》《td》请上传你的文件《/td》《td》《input type=file name=myfile》《/td》《/tr》 《tr》《td colspan=“ “》《input type=submit value=“上传“》《td》《/tr》 《/table》 《/form》 《/body》 《/》
uploadProcess php
代码如下 复制代码
《?php
//接收 $username=$_POST; if($file_size》 * * ){ echo “《script type= text/javascript 》window alert( 文件不能大于 M )《/script》“; exit(); }
//获取文件类型 $file_type=$_FILES; if($file_type!=“image/jpeg“ && $file_type!=“image/pjpeg“){ echo “文件类型只能是 jpg 格式“; exit(); }
//判断上传是否OK if(is_uploaded_file($_FILES “/file/up/“ $username; if(!file_exists($user_path)){ mkdir ($user_path); }
//$move_to_file=$user_path “/“ $_FILES; $move_to_file=$user_path “/“ time() rand( ) substr($file_true_name strripos($file_true_name “ “));
//echo $upload_file $move_to_file; //中文要转码 if(move_uploaded_file($upload_file iconv(“utf “ “gb “ “$move_to_file“))){ echo $_FILES “上传成功“; }else{ echo “上传失败“; } }else{ echo “上传失败“; }
?》
注意:
我举个例子大家就知道 比如一个图片文件 pic jpg 我们用 strrchr处理 strrchr(pic jpg ) 它将返回 jpg 明白了吗?该函数返回指定字符在该字符串最后出现的位置后的字符 配合 substr() 我们就可以取到jpg 这样我们就得到了文件的后缀名 来判断上传文件是否符合指定格式 本程序把指定的格式放在一个数组中 实际使用时可根据需要添加
lishixinzhi/Article/program/PHP/201311/20924
html网页上传文件的完整代码
html前端代码:
《html》
《body》
《form action=“upload-file.php“ method=“post“
enctype=“multipart/form-data“》
《label for=“file“》文件名:《/label》
《input type=“file“ name=“file“ id=“file“ /》
《br/》
《input type=“submit“ name=“submit“ value=“提交“ /》
《/form》
《/body》
《/html》
如果是ubuntu上部署apache2,你应该是php开发者吧,action=“upload-file.php
“ 中的upload-file.php改为你自己的后端php接收文件的逻辑代码即可!
这里提供upload-file.php后端接收文件的代码:
《?php
if ($_FILES 》 0)
{
echo “错误: “ . $_FILES . “《br /》“;
}
else
{
echo “文件名: “ . $_FILES . “《br /》“;
echo “类型: “ . $_FILES . “《br /》“;
echo “大小: “ . ($_FILES / 1024) . “ Kb《br /》“;
}
if (file_exists(“upload/“ . $_FILES))
{
echo $_FILES . “ 文件已经存在. “;
}
else
{
move_uploaded_file($_FILES,
“upload/“ . $_FILES);
echo “文件已经被存储到: “ . “upload/“ . $_FILES;
}
?》
代码很简单,我相信你应该能看懂,这里的 文件夹 upload/ 需要你自己手动创建,请确保文件路径正取!
我也是web开发者,有问题可继续追问我!或是加我工作室QQ(540144097),在群里向我提问!有问必答,望采纳……
asp文件上传:文件上传 源代码
《! #include FILE=“upload inc“ 》 《% dim upload file formName formPath iCount filename fileExt set upload=new upload_ xSoft 建立上传对象 formPath=“uploadimages/“ 在目录后加(/) if right(formPath )《》“/“ then formPath=formPath&“/“ iCount= for each formName in upload file 列出所有上传了的文件 set file=upload file(formName) 生成一个文件对象 if file filesize《 then response write “《font size= 》《br》请先选择你要上传的图片 《/font》“ response end end if
fileExt=lcase(right(file filename ))
if fileEXT《》“ jpg“ and fileEXT《》“ gif“ then response write “《font size= 》《br》文件格式只能为jpg和gif格式 《/font》“ response end end if randomize ranNum=int( *rnd)+ filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt filename =year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&fileExt if file FileSize》 then 如果 FileSize 》 说明有文件数据 file SaveAs Server mappath(filename) 保存文件 response write “《script》parent form img value= “&FileName &“ 《/script》“
iCount=iCount+ end if set file=nothing next set upload=nothing 删除此对象
Response Write “《img src= “&“ /UpLoad/UpLoadImages/“&FileName &“ onload = DrawImage(this) 》“ response end %》
下面是upload inc的代码
《SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT》 dim upfile_ xSoft_Stream Class upload_ xSoft dim Form File Version Private Sub Class_Initialize dim iStart iFileNameStart iFileNameEnd iEnd vbEnter iFormStart iFormEnd theFile dim strDiv mFormName mFormValue mFileName mFileSize mFilePath iDivLen mStr if Request TotalBytes《 then Exit Sub set Form=CreateObject(“Scripting Dictionary“) set File=CreateObject(“Scripting Dictionary“) set upfile_ xSoft_Stream=CreateObject(“Adodb Stream“) upfile_ xSoft_Stream mode= upfile_ xSoft_Stream type= upfile_ xSoft_Stream open upfile_ xSoft_Stream write Request BinaryRead(Request TotalBytes) vbEnter=Chr( )&Chr( ) iDivLen=inString( vbEnter)+ strDiv=subString( iDivLen) iFormStart=iDivLen iFormEnd=inString(iformStart strDiv) while iFormStart 《 iFormEnd iStart=inString(iFormStart “name=“““) iEnd=inString(iStart+ ““““) mFormName=subString(iStart+ iEnd iStart ) iFileNameStart=inString(iEnd+ “filename=“““) if iFileNameStart》 and iFileNameStart《iFormEnd then iFileNameEnd=inString(iFileNameStart+ ““““) mFileName=subString(iFileNameStart+ iFileNameEnd iFileNameStart ) iStart=inString(iFileNameEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv) if iEnd》iStart then mFileSize=iEnd iStart else mFileSize= end if set theFile=new FileInfo theFile FileName=getFileName(mFileName) theFile FilePath=getFilePath(mFileName) theFile FileSize=mFileSize theFile FileStart=iStart+ theFile FormName=FormName file add mFormName theFile else iStart=inString(iEnd+ vbEnter&vbEnter) iEnd=inString(iStart+ vbEnter&strDiv)
if iEnd》iStart then mFormValue=subString(iStart+ iEnd iStart ) else mFormValue=““ end if form Add mFormName mFormValue end if
iFormStart=iformEnd+iDivLen iFormEnd=inString(iformStart strDiv) wend End Sub
Private Function subString(theStart theLen) dim i c stemp upfile_ xSoft_Stream Position=theStart stemp=““ for i= to theLen if upfile_ xSoft_Stream EOS then Exit for c=ascB(upfile_ xSoft_Stream Read( )) If c 》 Then if upfile_ xSoft_Stream EOS then Exit for stemp=stemp&Chr(AscW(ChrB(AscB(upfile_ xSoft_Stream Read( )))&ChrB(c))) i=i+ else stemp=stemp&Chr(c) End If Next subString=stemp End function
Private Function inString(theStart varStr) dim i j bt theLen str InString= Str=toByte(varStr) theLen=LenB(Str) for i=theStart to upfile_ xSoft_Stream Size theLen if i》upfile_ xSoft_Stream size then exit Function upfile_ xSoft_Stream Position=i if AscB(upfile_ xSoft_Stream Read( ))=AscB(midB(Str )) then InString=i for j= to theLen if upfile_ xSoft_Stream EOS then inString= Exit for end if if AscB(upfile_ xSoft_Stream Read( ))《》AscB(MidB(Str j )) then InString= Exit For end if next if InString《》 then Exit Function end if next End Function
Private Sub Class_Terminate form RemoveAll file RemoveAll set form=nothing set file=nothing upfile_ xSoft_Stream close set upfile_ xSoft_Stream=nothing End Sub Private function GetFilePath(FullPath) If FullPath 《》 ““ Then GetFilePath = left(FullPath InStrRev(FullPath ““)) Else GetFilePath = ““ End If End function Private function GetFileName(FullPath) If FullPath 《》 ““ Then GetFileName = mid(FullPath InStrRev(FullPath ““)+ ) Else GetFileName = ““ End If End function
Private function toByte(Str) dim i iCode c iLow iHigh toByte=““ For i= To Len(Str) c=mid(Str i ) iCode =Asc(c) If iCode《 Then iCode = iCode + If iCode》 Then iLow = Left(Hex(Asc(c)) ) iHigh =Right(Hex(Asc(c)) ) toByte = toByte & chrB(“&H“&iLow) & chrB(“&H“&iHigh) Else toByte = toByte & chrB(AscB(c)) End If Next End function End Class
lishixinzhi/Article/program/net/201311/14198