文件上传 图片上传

 

<input type="file" name="myFile"/>

uploadFile.PostedFile.SaveAs(path);

public void UploadFile(object sender , EventArgs E)
  {
   //检查上传文件不为空
   if(myFile.PostedFile!=null)
   {    
    string nam = myFile.PostedFile.FileName ;
    //取得文件名(抱括路径)里最后一个"."的索引
    int i= nam.LastIndexOf(".");
    //取得文件扩展名
    string newext =nam.Substring(i);
    //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
    DateTime now = DateTime.Now;
    string newname=now.DayOfYear.ToString()+myFile.PostedFile.ContentLength.ToString();

    //保存文件到你所要的目录,这里是IIS根目录下的uploadfiles目录
    //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"/"必须用"//"代替
    myFile.PostedFile.SaveAs(Server.MapPath(".//UpLoadFiles//"+newname+newext));
    
    //得到这个文件的相关属性:文件名,文件类型,文件大小
    fname.Text=myFile.PostedFile.FileName;
    fenc.Text=myFile.PostedFile.ContentType ;
    fsize.Text=myFile.PostedFile.ContentLength.ToString();
    Image1.ImageUrl = "
http://localhost/web/news/uploadfiles/"+newname+newext;
   }
  }

<input type="file" name="upLoad"/>

<script>
void GetThumbnailImage(int width,int height,string strInfo,int left,int right)
{
string file="Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('//')+1);
string newfile="Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('//')+1)+".jpg";
string strAdd=strInfo;
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(file));
System.Drawing.Image thumbnailImage =
oldimage.GetThumbnailImage(width, height,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Response.Clear();
Bitmap output=new Bitmap(thumbnailImage);
Graphics g=Graphics.FromImage(output);
g.DrawString(strAdd,new Font("Courier New", 14),new SolidBrush(Color.Red),left,right);
output.Save(Server.MapPath(newfile),System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "image/gif";
ImgPreview.Visible=true;
ImgPreview.ImageUrl=newfile;
}

uploadFile.PostedFile.SaveAs(path);




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值