如何在mootools中处理上传文件?
我已经搜索过这个,我不能在文件上传中使用ajax,但我需要做的就是通过ajax处理我的文件,然后将其传递到我的控制器(我在其中创建和对象文件保存在目录中),那么如何才能我通过 ajax mootols 处理上传文件,我已经这样做了,但什么也没发生,请不要插件,我只需要有人指导我,
这是我的代码
#f1_upload_process{
z-index:100;
position:absolute;
visibility:hidden;
text-align:center;
width:400px;
margin:0px;
padding:0px;
background-color:#fff;
border:1px solid #ccc;
}
</style>
<p id="f1_upload_process">Loading...<br/></p>
<p id="result"></p>
<form method="post" action="" enctype="multipart/form-data">
<label for="file">Subir un archivo</label>
<input type="file" name="file" id="fileArchivo" />
<input type="submit" name="submit" id="btnSubir" value="upload file" />
<iframe name="iframUpload" id="iframeUpload" type="file" style="display:none"></iframe>
</form>
mootools ajax
window.addEvent("domready",function(){
cargarIndex();
});
function cargarIndex()
{
var prueboRequest = new Request({
method: 'POST',
url: '../CONTROLLER/inicio.php',
onRequest: function() {},
onSuccess: function(texto, xmlrespuesta){
document.getElementById('subirarchivo').innerHTML= texto;
$('btnSubir').addEvent('click',function(){beginUploading()});
},
onFailure: function(){alert('Error!');}
}).send();
}
function beginUploading(){
var prueboRequest = new Request({
method: 'POST',
url: '../Controller/ControllerSubirArchivo.php',
onRequest: function() {},
onSuccess: function(texto, xmlrespuesta){
onFailure: function(){alert('Error!');}
}).send();
我已经搜索过,但我发现的只是这个,但是jquery,我想要类似的东西:
$(function(){
var btnUpload=$('#upload');
var status=$('#status');
new AjaxUpload(btnUpload, {
action: 'upload-file.php',
//Name of the file input box
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// check for valid file extension
status.text('Only JPG, PNG or GIF files are allowed');
return false;
}
status.text('Uploading...');
},
onComplete: function(file, response){
//On completion clear the status
status.text('');
//Add uploaded file to list
if(response==="success"){
$('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});
});
}
I already search about this and I cannot use ajax in file uploading, but all I need to do is process my file through an ajax then pass it to my controller (where I created and object file to save in a directory), so how can I process an upload file trough an ajax mootols, I already do it and nothings happens, no plugins please, I need just to someone guide me
this is my code
#f1_upload_process{
z-index:100;
position:absolute;
visibility:hidden;
text-align:center;
width:400px;
margin:0px;
padding:0px;
background-color:#fff;
border:1px solid #ccc;
}
</style>
<p id="f1_upload_process">Loading...<br/></p>
<p id="result"></p>
<form method="post" action="" enctype="multipart/form-data">
<label for="file">Subir un archivo</label>
<input type="file" name="file" id="fileArchivo" />
<input type="submit" name="submit" id="btnSubir" value="upload file" />
<iframe name="iframUpload" id="iframeUpload" type="file" style="display:none"></iframe>
</form>
mootools ajax
window.addEvent("domready",function(){
cargarIndex();
});
function cargarIndex()
{
var prueboRequest = new Request({
method: 'POST',
url: '../CONTROLLER/inicio.php',
onRequest: function() {},
onSuccess: function(texto, xmlrespuesta){
document.getElementById('subirarchivo').innerHTML= texto;
$('btnSubir').addEvent('click',function(){beginUploading()});
},
onFailure: function(){alert('Error!');}
}).send();
}
function beginUploading(){
var prueboRequest = new Request({
method: 'POST',
url: '../Controller/ControllerSubirArchivo.php',
onRequest: function() {},
onSuccess: function(texto, xmlrespuesta){
onFailure: function(){alert('Error!');}
}).send();
I already search but all I have found is this but with jquery, and I want something similar to:
$(function(){
var btnUpload=$('#upload');
var status=$('#status');
new AjaxUpload(btnUpload, {
action: 'upload-file.php',
//Name of the file input box
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// check for valid file extension
status.text('Only JPG, PNG or GIF files are allowed');
return false;
}
status.text('Uploading...');
},
onComplete: function(file, response){
//On completion clear the status
status.text('');
//Add uploaded file to list
if(response==="success"){
$('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Dimitar Christoff 所说,目前还没有办法在没有跨浏览器问题的情况下上传 ajax 文件……
我会推荐 plupload 项目,这样你就可以确定它是跨浏览器的。来自 forge 的插件也可以做到这一点,但如今分离 javascript 文件上传库是一个好主意。考虑到 HTML5 API 的实现在很多浏览器上仍然是部分的,您可能需要尽快更新脚本......
As Dimitar Christoff said, no way to have an ajax file upload without a little bit of cross browser headache for now…
I would recommend the plupload project so you're sure it's cross browser. A plugin from the forge could also do the trick but separating the javascript file upload library is a good idea these days. Considering that the implementation of the HTML5 API is still partial on a lot of browsers, you may have to update the script soon…