当前位置:首页 » 文件管理 » 图片上传功能

图片上传功能

发布时间: 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 05:08:31 浏览:798
javajdbc数据库连接 发布:2024-10-20 04:50:02 浏览:9
android获取子控件 发布:2024-10-20 04:11:13 浏览:241
java接口的作用和意义 发布:2024-10-20 04:07:46 浏览:171
安卓如何用耳机内录 发布:2024-10-20 04:01:31 浏览:242
asp无组件上传进度 发布:2024-10-20 03:59:59 浏览:110
服务器依据端口搭建多个网站 发布:2024-10-20 03:56:08 浏览:748
o圈压缩量 发布:2024-10-20 03:37:00 浏览:857
光遇为什么显示登入服务器错误 发布:2024-10-20 03:18:02 浏览:969
pythonbase模块 发布:2024-10-20 03:11:40 浏览:66