圖片上傳控制項
A. ASP.NET上傳控制項上傳圖片
要嗎你就是隨機生成字元串,要嗎就是以時間為名字,精確到毫秒就應該差不多了啊
B. 使用FileUpload控制項,上傳圖片到images下的upload文件夾中,代碼要添加什麼才能上傳
protected void Button1_Click(object sender, EventArgs e)
{
string cat = Server.MapPath(@"images/upload/");
if (System.IO.Directory.Exists(cat) == false)
{
System.IO.Directory.CreateDirectory(cat);
}
if (FileUpload1.HasFile == true)
{
FileUpload1.SaveAs(cat + FileUpload1.FileName);
Response.Write("<script> alert('上傳成功!')</script>");
Label1.Text = "images/upload/" + FileUpload1.FileName.ToString();
}
}
C. 用FileUpload控制項怎麼實現多圖片上傳
單存的FileUpload控制項無法實現多圖片上傳!要做成那種多選效果一般現在用 as編寫的flash控制項!效果相當不錯!!你可以在網上找找
D. 上傳圖片控制項的問題
剛了你的代碼,運行了一下,沒有發現你說的問題,點擊瀏覽之後,文本框中會保留路徑,在點擊div後文本框中的值會改變,但不會情空文本框,敢問你用的IE版本是那個,是否是因為存在瀏覽器兼容性問題
E. 怎麼把圖片路徑賦到上傳控制項FileUpload中
好像不太好找
一般都用fileupload
如果特殊需要
就自定義唄
F. ext js 上傳圖片控制項
在服務端判斷了,假設你的客戶端控制項 name = 」photo-path「
服務端可以寫成以下:
HttpPostedFile postedFile = Request.Files["photo-path"];//獲取上傳信息對象
string filename = postedFile.FileName;//獲取上傳的文件路徑
string sExtension = filename.Substring(filename.LastIndexOf('.'));//獲取拓展名
然後就可以判斷是否正確了,但是通過擴展名判斷文件類型比較不靠譜了,因為擴展名是可以變更的。
G. 急求一個圖片上傳控制項
謝謝樓上的回帖,但是你寫的這個功能,我可以實現的,關鍵就是怎麼可以在預覽中,有一個框,可以調整這個框的大小,只要被這個框選中的區域,點一下確認後,就可以生產一個選中區域的圖片,就是校內上傳頭像的那個控制項或者是方法。在這里我還是要感謝一下樓上的代碼。謝謝你了啊!!在線等,我很急的啊!!!
H. Dev控制項的ASPxUploadControl怎麼實現圖片上傳
MaxFileSizeErrorText="圖片大小不得超過2M!" ="不支持的圖片格式!">
</ValidationSettings>
</dx:ASPxUploadControl>js://上傳控制項賦值給圖片控制項顯示
function Uploader_OnFileUploadComplete(args) {
if (args.isValid) {
var imgSrc = decodeURI(args.callbackData);
ASPxClientImage.Cast('previewImage').SetImageUrl(imgSrc);
ASPxClientHiddenField.Cast("HiddenIds").Set("ImageUrl", imgSrc);}}function BeginUpload() {
var uploader = ASPxClientUploadControl.Cast('uploader');
var reg = /[@#\$%\^&\*]+/g;
if (uploader.GetText(0) != "") {
if (!reg.test(uploader.GetText(0))) {
uploader.Upload();} else {alert("文件名不能含有非法字元!");
uploader.ClearText();}}}後台://文件上傳protected void FileToUpload_FileUploadComplete(object sender, DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs e){//刪除舊相片
//保存新相片
e.CallbackData = SavePostedFile(e.UploadedFile);}private string SavePostedFile(UploadedFile uploadFile){//設置圖片地址
const string UploadDirectory = "../../UploadFile/GuestPhoto/";
//得到伺服器相片地址
I. 使用FileUpLoad上傳圖片 並且上傳時把圖片顯示到Image控制項中 請問你有具體的代碼嗎,能否發過來看看
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;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//檢查上傳文件的格式是否有效
if(this.FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("上傳圖片格式無效!");
return;
}
//生成原圖
Byte[] oFileByte = new byte[this.FileUpload1.PostedFile.ContentLength];
System.IO.Stream oStream = this.FileUpload1.PostedFile.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream);
int oWidth = oImage.Width; //原圖寬度
int oHeight = oImage.Height; //原圖高度
int tWidth = 100; //設置縮略圖初始寬度
int tHeight = 100; //設置縮略圖初始高度
//按比例計算出縮略圖的寬度和高度
if(oWidth >= oHeight)
{
tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth)
/ Convert.ToDouble(oWidth)));
}
else
{
tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight)
/ Convert.ToDouble(oHeight)));
}
//生成縮略原圖
Bitmap tImage = new Bitmap(tWidth,tHeight);
Graphics g = Graphics.FromImage(tImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//設置高質量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//設置高質量,低速度呈現平滑程度
g.Clear(Color.Transparent); //清空畫布並以透明背景色填充
g.DrawImage(oImage,new Rectangle(0,0,tWidth,tHeight),
new Rectangle(0,0,oWidth,oHeight),GraphicsUnit.Pixel);
string oFullName = Server.MapPath(".") + "/" + "o" +
DateTime.Now.ToShortDateString().Replace("-","") + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + ".jpg"; //保存原圖的物理路徑
string tFullName = Server.MapPath(".") + "/" + "t" +
DateTime.Now.ToShortDateString().Replace("-","") + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + ".jpg"; //保存縮略圖的物理路徑
try
{
//以JPG格式保存圖片
oImage.Save(oFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
tImage.Save(tFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(Exception ex)
{
throw ex;
}
finally
{
//釋放資源
oImage.Dispose();
g.Dispose();
tImage.Dispose();
}
}
}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;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//檢查上傳文件的格式是否有效
if(this.FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("上傳圖片格式無效!");
return;
}
//生成原圖
Byte[] oFileByte = new byte[this.FileUpload1.PostedFile.ContentLength];
System.IO.Stream oStream = this.FileUpload1.PostedFile.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.FromStream(oStream);
int oWidth = oImage.Width; //原圖寬度
int oHeight = oImage.Height; //原圖高度
int tWidth = 100; //設置縮略圖初始寬度
int tHeight = 100; //設置縮略圖初始高度
//按比例計算出縮略圖的寬度和高度
if(oWidth >= oHeight)
{
tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth)
/ Convert.ToDouble(oWidth)));
}
else
{
tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight)
/ Convert.ToDouble(oHeight)));
}
//生成縮略原圖
Bitmap tImage = new Bitmap(tWidth,tHeight);
Graphics g = Graphics.FromImage(tImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//設置高質量插值法
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//設置高質量,低速度呈現平滑程度
g.Clear(Color.Transparent); //清空畫布並以透明背景色填充
g.DrawImage(oImage,new Rectangle(0,0,tWidth,tHeight),
new Rectangle(0,0,oWidth,oHeight),GraphicsUnit.Pixel);
string oFullName = Server.MapPath(".") + "/" + "o" +
DateTime.Now.ToShortDateString().Replace("-","") + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + ".jpg"; //保存原圖的物理路徑
string tFullName = Server.MapPath(".") + "/" + "t" +
DateTime.Now.ToShortDateString().Replace("-","") + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()
+ DateTime.Now.Millisecond.ToString() + ".jpg"; //保存縮略圖的物理路徑
try
{
//以JPG格式保存圖片
oImage.Save(oFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
tImage.Save(tFullName,System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch(Exception ex)
{
throw ex;
}
finally
{
//釋放資源
oImage.Dispose();
g.Dispose();
tImage.Dispose();
}
}
}