當前位置:首頁 » 文件管理 » 圖片上傳功能

圖片上傳功能

發布時間: 2022-01-29 22:08:18

『壹』 如何實現編輯器在線圖片文件上傳功能

一般情況都是路徑不對。

如果你使用的不是ueditor自帶的上傳類,那就就需要在調用頁配置如下參數:

window.UEDITOR_HOME_URL='Public/ueditor1_3_6/';
window.onload=function(){
window.UEDITOR_CONFIG.imageUrl="/News/uploadimg"; //上傳圖片類路徑。
window.UEDITOR_CONFIG.fileUrl="/News/uploadfile"; //上傳文件類路徑。
window.UEDITOR_CONFIG.videoPath="/News/uploadvideo"; //上傳視頻類路徑。
window.UEDITOR_CONFIG.imagePath='upload/images/'; //修復返回圖片路徑。
window.UEDITOR_CONFIG.filePath='upload/txtfiles/'; //修復文件返迴路徑。
window.UEDITOR_CONFIG.videoPath='upload/video/'; //修復文件返迴路徑。
UE.getEditor('editor');
}

ueditor官方文檔有很詳細介紹的,以上配置在ueditor.config.js文件裡面都能找到。

我現在在做的一個項目也是使用了這個編輯器,

使用方法都一樣,自負的傢伙!~( ^_^ )/~~拜拜!~~~~

『貳』 上傳圖片怎麼弄

上傳那?空間?

『叄』 圖片上傳功能的實質

是的.應該都是像你說的那樣做的。當然你也可以直接將圖片存儲資料庫表中的一個欄位里。不過不建議這么做。

貼一段C#代碼,不知道對你是否有用
HttpFileCollection files = HttpContext.Current.Request.Files;
for (int iFile = 0; iFile < files.Count; iFile++)
{
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
int fileSize;
fileName = Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
//驗證後綴名和文件大小
fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
fileSize = postedFile.ContentLength/1024;
if (!string.IsNullOrEmpty(fileExtension) && GlobalVars.ALLOWED_EXT.IndexOf(fileExtension) > -1
&& fileSize <= GlobalVars.MAX_FILE_SIZE)
{
DateTime now = DateTime.Now;
string path = Request.PhysicalApplicationPath + "UploadFile/"
+ now.Year.ToString() + "/" + now.Month.ToString()+ "/";
string rpath = "UploadFile/" + now.Year.ToString() + "/" + now.Month.ToString() + "/";
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
path += now.ToString("yyyyMMddHHmmssffff") + fileName;
rpath += now.ToString("yyyyMMddHHmmssffff") + fileName;
try
{
postedFile.SaveAs(path);
}
catch (Exception) {
ToResponse("保存文件出錯!");
}
BLL.SystemBase.SystemFile system = new BLL.SystemBase.SystemFile();
long id;
try
{
id = system.Add(fileName, rpath, Convert.ToInt64(Session["UserID"]), fileSize);
ToResponse(id.ToString());

}
catch (NSException ex) {
ToResponse(ex.Message);
}

}
else {
if (fileSize > GlobalVars.MAX_FILE_SIZE)
{
ToResponse("您上傳的文件大小為:" + fileSize + "K,最大允許:" + GlobalVars.MAX_FILE_SIZE + "k");
}
else if (string.IsNullOrEmpty(fileExtension)||GlobalVars.ALLOWED_EXT.IndexOf(fileExtension) == -1)
{
ToResponse("文件格式有誤,允許的格式包括:" + GlobalVars.ALLOWED_EXT);
}
}
}
}

前面是生成文件名
postedFile.SaveAs(path);就是將圖片保存到了網站空間下的文件夾
保存好之後,在執行其他方法將圖片路徑保存到資料庫中

『肆』 在做圖片上傳功能時,如何顯示客戶端圖片

我明白樓主的意思,就是實現預覽功能

網上有很多這樣的例子,你直接搜索"js 上傳圖片預覽"就行

給你一個簡單的例子:

<formaction=""method="post"enctype="multipart/form-data"name="form1">
<imgsrc=""name="image"border=0id="img"/>
<br/>
<inputname="picture"type="file"id="picture"onchange="img.src=this.value"/>
</form>

IE下沒問題

『伍』 上傳與顯示圖片的功能

<%
'----------------------------------------------------------
'***************** 風聲無組件上傳類 2.0 *****************
'作者:風聲
'郵件:[email protected]
'版權:版權全體,源代碼公開,各種用途均可免費使用
'**********************************************************
'----------------------------------------------------------
Class UpLoadClass

Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem

Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property

Public Property Get Error
Error=p_Error
End Property

Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End Property

Public Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End Property

Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property

Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property

Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 153600
p_FileType = "jpg/gif"
p_SavePath = ""
p_AutoSave = 2
strDate = replace(cstr(Date()),"-","")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub

Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End Sub

Public Sub Open()
on error resume next
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData

Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)

intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)

Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()

p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz

intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)

if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if

binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub

Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function

Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function

Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function

Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binForm.Read(objForm(Item&"_Size"))
end if
End Function

Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function

Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function

Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function

End Class

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

set up = new UploadClass '建立上傳對象
up.AutoSave = 0 '取無重復的伺服器時間字元串為文件名自動保存文件
up.SavePath = filePath '文件保存的目錄
up.FileType = "jpg/jpeg/gif/png" '設置運行上傳的文件類型
up.MaxSize = 1024 * 1024 '最大 1M
up.Open()

Uperr = up.Error '返回錯誤代碼,0則無錯

name = up.Form("name") '獲取文本框值,文件上傳不能用request獲取

%>

以上 夠詳細了吧,自己看著用。還有文件上傳的form要指定 enctype="multipart/form-data"

『陸』 java怎樣實現圖片上傳功能

圖片不會那麼的保存到資料庫中。
而是把圖片放到文件系統,或者你指定的一個位置。
然後再資料庫中存放的為圖片的路徑

『柒』 上傳圖片怎麼讓點擊圖片就能打開上傳圖片功能

上傳,之後然後js判斷是否成功 成功就 ajax 請求 訪問那個圖

『捌』 請問用Java 如何實現圖片上傳功能

自己寫程序來上傳位元組流文件很難的,用SmartUpload.jar包吧,專門用於JSP上傳下載的,唯一缺點就是中文支持不太好,不過你可以改一下原程序的字元集就行了。上網搜,沒有找我!我給你發

『玖』 如何進行多圖片上傳功能

·用input標簽並選擇type=file,記得帶上multiple,不然就只能單選圖片了
·綁定好input的change時間,
·重點就是如何處理這個change事件了,使用H5新的FileReader介面讀取文件並打成base64編碼,之後的事就是與後端同學交互著玩啦。

『拾』 怎麼實現圖片上傳前預覽功能呢

預覽圖片
預覽功能的基本設計思路:創建一個img元素,再把文件域的value值賦值給img元素的src屬性。

<form name="form4" id="form4" method="post" action="#">

<input type="file" name="file4" id="file4" ōnchange="preview4()" />

<img id="pic4" src="" alt="圖片在此顯示" width="120"/>
</form>

<scrīpt type="text/javascrīpt">

function preview4(){

var x = document.getElementById("file4");

var y = document.getElementById("pic4");

if(!x || !x.value || !y)

return;

var patn = /\.jpg$|\.jpeg$|\.gif$/i;

if(patn.test(x.value)){

y.src = "file://localhost/" + x.value;

}

else{ alert("您選擇的似乎不是圖像文件。"); }

}

</scrīpt>

試下效果:


如果你用的是Firefox(或Opera),可能會發現什麼也沒有發生。是的,很不幸Firefox的安全策略不允許我們顯示一個用戶的本地圖像文件。不知道他們為什麼要這么做,我個人覺得圖像文件並不會造成嚴重的安全性問題。即使是不久前比較熱門的那個會引起Windows崩潰的jpeg文件,要顯示它的前提條件是用戶自己選擇了這個文件或者你知道這個文件在用戶硬碟上的准確路徑。所以我想這種策略很可能來自於一個「懶惰」的開發人員,他並不想多寫一些程序來區分這個本地文件是一個圖像文件還是一個惡意文件,Firefox對安全性的要求讓他們有些過於敏感了。

讓Firefox顯示本地文件的唯一辦法就是修改它的默認安全策略:

在Firefox的地址欄中輸入「about:config」
繼續輸入「security.checkloari」
雙擊下面列出來的一行文字,把它的值由true改為false
然後你可以再試試上面預覽,everything works well!可惜的是我們並不能要求所有的用戶都去修改這個值(更不用說修改的過程還挺麻煩),所以這對我們來說毫無意義。我們能做的也許就是接受Firefox不能預覽本地圖片這種「可笑」的局面。

用DOM來創建對象
在上面的XHTML代碼中,我們為了預覽圖片,事先加入了一個沒有設置src的img對象。除去不美觀、代碼冗餘之外,如果用戶瀏覽器不支持Javascrīpt,他不僅無法使用這個功能,還要接受頁面上一個永遠不會顯示出來的破圖。要解決這個問題,我們就需要在「運行時」再生成這個img對象,途徑還是DOM。

<form name="form5" id="form5" method="post" action="#">

<input type="file" name="file5" id="file5" ōnchange="preview5()"/>

</form>

<scrīpt type="text/javascrīpt">

function preview5(){

var x = document.getElementById("file5");

if(!x || !x.value)

return;

var patn = /\.jpg$|\.jpeg$|\.gif$/i;

if(patn.test(x.value)){

var y = document.getElementById("img5");

if(y){ y.src = 'file://localhost/' + x.value; }

else{

var img=document.createElement('img');

img.setAttribute('src','file://localhost/'+x.value);

img.setAttribute('width','120');

img.setAttribute('height','90');

img.setAttribute('id','img5');

document.getElementById('form5').appendChild(img);

}

}

else{ alert("您選擇的似乎不是圖像文件。"); }

}

</scrīpt>

熱點內容
光遇為什麼顯示登入伺服器錯誤 發布:2024-10-20 03:18:02 瀏覽:968
pythonbase模塊 發布:2024-10-20 03:11:40 瀏覽:65
編輯c文件編譯連接運行 發布:2024-10-20 03:02:58 瀏覽:225
網路編程的工作 發布:2024-10-20 03:02:53 瀏覽:191
android手機uuid 發布:2024-10-20 03:02:16 瀏覽:951
圖解linux安裝 發布:2024-10-20 03:01:25 瀏覽:288
androidview動態添加 發布:2024-10-20 03:00:39 瀏覽:406
python數字轉字元 發布:2024-10-20 03:00:02 瀏覽:270
墨香資料庫 發布:2024-10-20 02:39:33 瀏覽:103
傳祺gs7選哪個配置 發布:2024-10-20 02:37:22 瀏覽:646