2
上传文件我希望在用户在输入文件中用$ .ajax选择一个文件时异步上传文件。但是,调用返回索引的php未定义。 jQuery代码是下一个:
$("#urlimatge").change(function(){
var filename = $("#urlimatge").val();
$.ajax({
type: "POST",
url: "utils/uploadtempimg.php",
enctype: 'multipart/form-data',
data: {'urlimatge' : filename },
success: function(response){
alert(response);
}
});
});
和recibe呼叫的PHP:
$image = new gestorimatges();
$target_path = $image->uploadTemp($_FILES['urlimatge']['name'],$_FILES['urlimatge']['tmp_name']);
感谢
谢谢我对iframe使用了类似的解决方案。我调用iframe并使用jquery修改action的值。 – 2012-04-21 23:07:55
以下不适用于我:我正在使用多文件上传器来选择多个文件。文件仅通过表单发送。它现在在我的Firefox浏览器中打开一个新的“标签”.... \t
– rajeev 2012-12-19 01:16:47你可能会想使用工具,如uploadify了点。
来源
2012-04-21 16:31:39 Broncha
闪光...只是没有理由让人们支持Flash才能使用您的形式,它是如何工作Uploadify 。 – Jasper 2012-04-21 16:44:40
还有很多其他工具不使用闪光..检查此.. http://superdit.com/2010/06/29/10-jquery-ajax-file-uploader-plugins/ – Broncha 2012-04-21 17:03:21
您无法将$ _FILE从AJAX传递到PHP。
我会建议使用plugin
它将使你的生活更轻松:) Here is a video tutorial to help too
来源
2012-04-21 16:33:42 JREAM
好的谢谢,我可以通过足够要上传文件的参数,例如名称或url?我会尝试插件谢谢。 – 2012-04-21 16:38:40
是的,你可以传递额外的参数和一切,你只需在params中添加:{anything:'youwant'} – JREAM 2012-04-21 16:40:44