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