您的位置:首页 > Web前端 > JavaScript

Extjs文件上传

2013-05-27 22:12 225 查看
head>
03.
<title>Uploading</title>

04.
<linkrel=
"stylesheet"

type=
"text/css"
href=
"../../resources/css/ext-all.css"
/>

05.

06.
<!--GC-->

07.
<!--LIBS-->

08.
<scripttype=
"text/javascript"

src=
"../../adapter/ext/ext-base.js"
></script>

09.
<!--ENDLIBS-->

10.

11.
<scripttype=
"text/javascript"

src=
"../../ext-all.js"
></script>

12.

13.
<scripttype=
"text/javascript"

src=
"upload.js"
></script>

14.
<linkrel=
"stylesheet"

type=
"text/css"
href=
"forms.css"
/>


15.

16.
<!--CommonStyles
for
theexamples-->


17.
<linkrel=
"stylesheet"

type=
"text/css"
href=
"../examples.css"
/>


18.
</head>

19.
<body>

20.
<scripttype=
"text/javascript"

src=
"../examples.js"
></script>

21.
<!--EXAMPLES-->

22.
<h1>Upload
with
Forms</h1>

23.

24.
<p>Thejsisnotminifiedsoitisreadable.See

25.
<ahref=
"upload.js"
>upload.js</a>.</p>

26.
<p></p>

27.
<p><ahref=
"javascript:window.location.reload();"
>reload</a></p>

28.
</body>

29.
</html>


upload.js

viewsource

print?

01.
Ext.QuickTips.init();

02.
Ext.form.Field.prototype.msgTarget=
'side'
;

03.
Ext.onReady(
function
(){

04.
var

form=
new

Ext.form.FormPanel({

05.
baseCls:
'x-plain'
,

06.
labelWidth:80,

07.
url:
'upload.php'
,

08.
fileUpload:
true
,

09.
defaultType:
'textfield'
,

10.

11.
items:[{

12.
xtype:
'textfield'
,

13.
fieldLabel:
'FileName'
,

14.
name:
'userfile'
,

15.
inputType:
'file'
,

16.
allowBlank:
false
,

17.
blankText:
'Filecan\'tnotempty.'
,


18.
anchor:
'90%'
//anchorwidthbypercentage

19.
}]

20.
});

21.

22.
var

win=
new

Ext.Window({

23.
title:
'Uploadfile'
,

24.
width:400,

25.
height:200,

26.
minWidth:300,

27.
minHeight:100,

28.
layout:
'fit'
,

29.
plain:
true
,

30.
bodyStyle:
'padding:5px;'
,

31.
buttonAlign:
'center'
,

32.
items:form,

33.

34.
buttons:[{

35.
text:
'Upload'
,

36.
handler:
function
(){

37.
if
(form.form.isValid()){

38.
Ext.MessageBox.show({

39.
title:
'Pleasewait'
,

40.
msg:
'Uploading...'
,

41.
progressText:
''
,

42.
width:300,

43.
progress:
true
,

44.
closable:
false
,

45.
animEl:
'loding'

46.
});

47.
form.getForm().submit({

48.
success:
function
(form,action){


49.
Ext.Msg.alert(
'Messagefromextjs.org.cn'
,action.result.msg);

50.
win.hide();

51.
},

52.
failure:
function
(){

53.
Ext.Msg.alert(
'Error'
,
'Fileuploadfailure.'
);

54.
}

55.
})

56.
}

57.
}

58.
},{

59.
text:
'Close'
,

60.
handler:
function
(){win.hide();}

61.
}]

62.
});

63.
win.show();

64.
});


upload.php

viewsource

print?

01.
<?php

02.
//上传文件全称

03.
$uploadfile=
"upload_files/"
.basename($_FILES[
'userfile'
][
'name'
]);

04.

05.
$message=
""
;

06.
if

(@move_uploaded_file($_FILES[
'userfile'
][
'tmp_name'
],$uploadfile)){

07.
$message=
"Filewassuccessfullyuploaded."
;

08.
}

09.
else

10.
{

11.
$message=
"Possiblefileuploadattack!"
;

12.
}

13.

14.
print
"{success:true,msg:'"
.$message.
"'}"
;

15.
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: