fakepath上传成功了吗(Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事)

:暂无数据 2026-09-04 16:10:01 :0

fakepath上传成功了吗(Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事)

大家好,今天小编来为大家解答以下的问题,关于fakepath上传成功了吗,Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事这个很多人还不知道,现在让我们一起来看看吧!

本文目录

Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事

倒是不难,但是应用程序要做成工程的这里怎么写的下?
以下代码仅供参考!·
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//初始化文件夹信息
InitFolderInfo();
//初始化上传限制信息
InitUploadLimit();
//初始化列表框控件文件列表信息
InitFileList();
}
}
#region 初始化文件夹信息
private void InitFolderInfo()
{
//从config中读取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings.ToString();
//如果上传文件夹不存在,则根据config创建一个
if(!Directory.Exists(Server.MapPath(strFileUpladPath)))
{
Directory.CreateDirectory(Server.MapPath(strFileUpladPath));
}
//将虚拟路径转换为物理路径
string strFilePath = Server.MapPath(strFileUpladPath);
//从config里读取文件夹容量限制
double iFolderSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings);
//声明文件夹已经使用的容量
double iFolderCurrentSize = 0;
//获取文件夹中的所有文件
FileInfo arrFiles = new DirectoryInfo(strFilePath).GetFiles();
//循环文件获已经使用的容量
foreach (FileInfo fi in arrFiles)
{
iFolderCurrentSize += Convert.ToInt32(fi.Length / 1024);
}
#region 第二种获得文件夹使用大小的方法
//DirectoryInfo dir = new DirectoryInfo(strFilePath);
//foreach (FileSystemInfo fi in dir.GetFileSystemInfos())
//{
// FileInfo finf = new FileInfo(fi.FullName);
// iFolderCurrentSize += Convert.ToInt32(finf.Length / 1024);
//}
#endregion
//把文件夹容量和以用文件夹容量赋值给标签
lbl_FolderInfo.Text = string.Format("文件夹容量限制:M,已用容量:KB", iFolderSizeLimit / 1024, iFolderCurrentSize);
}
#endregion
#region 初始化上传限制信息
private void InitUploadLimit()
{
//从config中读取上传文件夹类型限制并根据逗号分割成字符串数组
string.ToString().Split(’,’);
//从config中读取上传文件大小限制
double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings);
//遍历字符串数组把所有项加入项目编号控件
for (int i = 0; i 《 arrFileTypeLimit.Length; i++)
{
bl_TileTypeLimit.Items.Add(arrFileTypeLimit.ToString());
}
//把文件大小限制赋值给标签
lab_FileSizeLimit.Text = string.Format("M", iFileSizeLimit / 1024);
}
#endregion
#region 初始化列表框控件文件列表信息
private void InitFileList()
{
//从config中获取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings.ToString();
//将虚拟路径转换为物理路径
string strFilePath = Server.MapPath(strFileUpladPath);
//读取上传文件夹下所有文件
FileInfo arrFile = new DirectoryInfo(strFilePath).GetFiles();
//把文件名逐一添加到列表框控件
foreach(FileInfo fi in arrFile)
{
lb_FileList.Items.Add(fi.Name);
}
}
#endregion
#region 判断文件大小限制
private bool IsAllowableFileSize()
{
//从web.config读取判断文件大小的限制
double iFileSizeLimit = Convert.ToInt32(ConfigurationManager.AppSettings) * 1024;
//判断文件是否超出了限制
if (iFileSizeLimit 》 FileUpload.PostedFile.ContentLength)
{
return true;
}
else
{
return false;
}
}
#endregion
#region 判断文件类型限制
protected bool IsAllowableFileType()
{
//从web.config读取判断文件类型限制
string strFileTypeLimit = ConfigurationManager.AppSettings.ToString();
//当前文件扩展名是否包含在这个字符串中
if(strFileTypeLimit.IndexOf(Path.GetExtension(FileUpload.FileName).ToLower()) 》0)
return true;
else
return false;
}
#endregion
#region 弹出警告消息
protected void ShowMessageBox(string strMessage)
{
Response.Write(string.Format("《script》alert(’’)《/script》",strMessage));
}
#endregion
#region 上传文件按钮事件
protected void btn_Upload_Click(object sender, EventArgs e)
{
//判断用户是否选择了文件
if (FileUpload.HasFile)
{
//调用自定义方法判断文件类型否符合
if (IsAllowableFileType())
{
//判断文件大小是否符合
if (IsAllowableFileSize())
{
//从web.config中读取上传路径
string strFileUploadPath = ConfigurationManager.AppSettings.ToString();
//从UploadFile控件中读取文件名
string strFileName = FileUpload.FileName;
//组合成物理路径
string strFilePhysicalPath = Server.MapPath(strFileUploadPath + "/") + strFileName;
//判断文件是否存在
if(!File.Exists(strFilePhysicalPath))
{
//保存文件
FileUpload.SaveAs(strFilePhysicalPath);
//更新列表框
lb_FileList.Items.Add(strFileName);
//更新文件夹信息
InitFolderInfo();
ShowMessageBox("上传成功!");
}
else
{
ShowMessageBox("文件已经存在!");
}
}
else
{
ShowMessageBox("文件大小不符合要求!");
}
}
else
{
ShowMessageBox("类型不匹配");
}
}
}
#endregion
#region 列表框事件
protected void lb_FileList_SelectedIndexChanged(object sender, EventArgs e)
{
//从config中读取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings.ToString();
//从列表框中读取选择的文件名
string strFileName = lb_FileList.SelectedValue;
//组合成物理路径
string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName;
//根据物理路径实例化文件信息类
FileInfo fi = new FileInfo(strFilePhysicalPath);
//或得文件大小和创建日期赋值给标签
lbl_FileDescription.Text = string.Format("文件大小:字节《br》《br》上传时间:《br》", fi.Length, fi.CreationTime);
//把文件名赋值给重命名文件框
tb_FileNewName.Text = strFileName;
}
#endregion
#region 下载文件按钮事件
protected void btn_DownLoad_Click(object sender, EventArgs e)
{
//从web.config读取文件上传路径
string strFileUploadPath = ConfigurationManager.AppSettings.ToLower();
//从列表框中读取选择的文件
string strFileName = lb_FileList.SelectedValue;
//组合成物理路径
string FullFileName = Server.MapPath(strFileUploadPath + "/") + strFileName;
FileInfo DownloadFile = new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream ";
Response.AppendHeader("Content-Disposition ", "attachment;filename= "
+ HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
#endregion
#region 删除文件
protected void btn_Delete_Click(object sender, EventArgs e)
{
//从config中读取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings.ToString();
//从列表框中读取选择的文件名
string strFileName = lb_FileList.SelectedValue;
//组合成物理路径
string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName;
//删除文件
System.IO.File.Delete(strFilePhysicalPath);
//更新文件列表框控件
lb_FileList.Items.Remove(lb_FileList.Items.FindByText(strFileName));
//更新文件夹信息
InitFolderInfo();
//更新文件描述信息
tb_FileNewName.Text = "";
//更新重命名文本框
lbl_FileDescription.Text = "";
//调用自定义消息提示
ShowMessageBox("删除成功!");
}
#endregion
#region 重命名文件
protected void btn_Rename_Click(object sender, EventArgs e)
{
//从web.config中读取文件上传路径
string strFileUpladPath = ConfigurationManager.AppSettings.ToString();
//从列表框中控件中读取选择的文件名
string strFileName = lb_FileList.SelectedValue;
//重命名文本框或得选择的文件名
string strFileNewName = tb_FileNewName.Text;
//组合成物理路径
string strFilePhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileName;
//组合成新物理路径
string strFileNewPhysicalPath = Server.MapPath(strFileUpladPath + "/") + strFileNewName;
//文件重命名,即获取新地址覆盖旧地址的过程
System.IO.File.Move(strFilePhysicalPath, strFileNewPhysicalPath);
//找到文件列表的匹配项
ListItem li = lb_FileList.Items.FindByText(strFileName);
//修改文字
li.Text = strFileNewName;
//修改值
li.Value = strFileNewName;
//调用自定义方法现实
ShowMessageBox("文件覆盖成功!");
}
#endregion
#region 下拉列表事件
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = Convert.ToInt32(DropDownList1.SelectedValue);
}
#endregion
}
源代码已发给你,如果有用就加点分!~

php 图片上传预览功能怎么实现

《form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"》
《input type="file" name="fileField" id="fileField" /》
《input type="submit" name="submit" id="submit" value="提交" /》
《/form》
《?php
if($_POST)
{
$file_gai = $_FILES;
$destination = basename($file_gai);
if(!move_uploaded_file ($filename_gai, $destination))
{
echo "《font color=’red’》移动文件出错!《/a》";
}else{
echo ("《script》location.href=’?file=".urlencode($destination)."’《/script》");
}
}if($_GET)
{
echo "《img src=’".urldecode($_GET)."’》";
}
?》

关于fakepath上传成功了吗和Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

fakepath上传成功了吗(Visual Studio 2008 中用fileupload控件上传图片时控件中的路径与alert(path);弹出来的路径不一样怎么回事)

本文编辑:admin

更多文章:


mariadb忘记密码(mysql用户密码忘记了怎么办)

mariadb忘记密码(mysql用户密码忘记了怎么办)

大家好,mariadb忘记密码相信很多的网友都不是很明白,包括mysql用户密码忘记了怎么办也是一样,不过没有关系,接下来就来为大家分享关于mariadb忘记密码和mysql用户密码忘记了怎么办的一些知识点,大家可以关注收藏,免得下次来找不

2026年10月15日 07:50

mysql端口号(如何查看自己数据库的端口号)

mysql端口号(如何查看自己数据库的端口号)

“mysql端口号”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看mysql端口号(如何查看自己数据库的端口号)!

2026年10月15日 06:30

printf打印16进制(C语言 十六进制怎么输出)

printf打印16进制(C语言 十六进制怎么输出)

大家好,今天小编来为大家解答以下的问题,关于printf打印16进制,C语言 十六进制怎么输出这个很多人还不知道,现在让我们一起来看看吧!

2026年10月15日 06:00

avantage怎么设置为中文(Avantage安装丢失GIT)

avantage怎么设置为中文(Avantage安装丢失GIT)

大家好,如果您还对avantage怎么设置为中文不太了解,没有关系,今天就由本站为大家分享avantage怎么设置为中文的知识,包括Avantage安装丢失GIT的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!

2026年10月15日 03:00

ospf协议的作用是什么(OSPF路由协议的作用是什么)

ospf协议的作用是什么(OSPF路由协议的作用是什么)

“ospf协议的作用是什么”相关信息最新大全有哪些,这是大家都非常关心的,接下来就一起看看ospf协议的作用是什么(OSPF路由协议的作用是什么)!

2026年10月15日 02:40

方案对比特效js(在一个网页中如何实现两个JS特效)

方案对比特效js(在一个网页中如何实现两个JS特效)

各位老铁们好,相信很多人对方案对比特效js都不是特别的了解,因此呢,今天就来为大家分享下关于方案对比特效js以及在一个网页中如何实现两个JS特效的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!

2026年10月15日 02:10

activex控件未注册怎么办(登陆视频监控网页时提示activex控件未注册,怎么解决)

activex控件未注册怎么办(登陆视频监控网页时提示activex控件未注册,怎么解决)

今天给各位分享登陆视频监控网页时提示activex控件未注册,怎么解决的知识,其中也会对登陆视频监控网页时提示activex控件未注册,怎么解决进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年10月14日 20:30

学生信息管理系统c语言(用C语言编程学生信息管理系统!)

学生信息管理系统c语言(用C语言编程学生信息管理系统!)

今天给各位分享用C语言编程学生信息管理系统!的知识,其中也会对用C语言编程学生信息管理系统!进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年10月14日 20:20

excel连接sql数据库教程(excel怎么连接sql数据库)

excel连接sql数据库教程(excel怎么连接sql数据库)

本篇文章给大家谈谈excel连接sql数据库教程,以及excel怎么连接sql数据库对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

2026年10月14日 19:40

null s brawl(null和空字符有区别吗)

null s brawl(null和空字符有区别吗)

今天给各位分享null和空字符有区别吗的知识,其中也会对null和空字符有区别吗进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年10月14日 19:00

最近更新

热刺vs马赛比赛(热刺赛程比分)
2026-10-15 09:10:01 浏览:0
热门文章

标签列表