gpt4 book ai didi

php - 使用 jquery $.ajax 和 php 上传文件

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:28 24 4
gpt4 key购买 nike

当用户在输入文件中选择文件时,我希望使用 $.ajax 异步上传文件。但是接收调用的 php 返回 undefined index 。接下来是 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);
}
});

});

和接收调用的 php:

$image =  new gestorimatges();
$target_path = $image->uploadTemp($_FILES['urlimatge']['name'],$_FILES['urlimatge']['tmp_name']);

谢谢

最佳答案

您不能将 $_FILE 从 AJAX 传递到 PHP。

我建议使用 plugin

它会让您的生活更轻松 :) Here is a video tutorial to help too

关于php - 使用 jquery $.ajax 和 php 上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10260865/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com