- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在描述我的问题之前,我确实在互联网和本网站上进行了搜索以找到解决方案。我发现一个问题与我的问题非常相似,但给出的答案甚至不太接近,所以我在这里写下我的问题。
问题是:
我有form
有一些输入字段加上 input type='file'
用于上传图像。这个表格里面jquery-ui dialog
,当我提交form
时,所有字段都按应有的方式响应,除了 input type='file'
对于图像,它从不携带图像的任何数据。
这是解释我的问题的代码:
update_form.php:
<form action="" class="fixed-dialog" method="post" id="customForm" enctype="multipart/form-data">
<input type="file" class="form-group input-field" accept="image/jpg,image/png,image/jpeg,image/gif" id="image" name="image" />
</form>
当用户点击Send
时按钮,此代码将触发(JQuery):
$("#send").click(function(){
var all = $("#customForm").serialize();
//the following condition is to check if all input fields were filled.
$.ajax({
type: "POST",
url: "includes/update_user_info.php",
data: all,
success: function(data){
if(data == 1){
alert("You have update data successfuly");
window.location = "index.php";
}else{
alert("there is an error");
}
}
});
});
这里是update_user_info.php:将图像从tmp文件移动到其他文件
$user_image = &$_FILES['image']['name'];
$user_image_type = &$_FILES['image']['type'];
$user_temp_image = &$_FILES['image']['tmp_name'];
if(isset($_FILES['image'])){
$_SESSION['errors'] = "it's set.\n";
//the next statement is empty, it should carry some data.
$_SESSION['errors'] .= $_FILES['image']['tmp_name'];
}else{
$_SESSION['errors'] = "NOT SET YET!!!";
}
$target = "./images/users_img/".$user_image;
$source = $_FILES['image']['tmp_name'];
// if($_FILES['image']['error'] == 0){
move_uploaded_file($_FILES['image']['tmp_name'],$target);
$_SESSION['errors'] .= "Target is: ".$_FILES['image']['tmp_name'];
if(is_uploaded_file($_FILES['image']['tmp_name'])){
$_SESSION['errors'] .= "Target is: it Worked";
echo 1;
}else{
$_SESSION['errors'] .= "Target is: NOT WORKING";
echo 1;
}
// }else{
// $_SESSION['errors'] .= "Something went Wrong!!";
// echo 1;
// }
当我尝试回显 $_FILES['image']['tmp_name']
时,或['name']
或['error']
,它总是给我一个错误:
未定义索引:名称/tmp_name/或错误,
<强> isset($_FILES['image'])
= TRUE。,但是:
<强> $_FILES['image']['name']
为空。
任何帮助将不胜感激。
谢谢。
最佳答案
我不相信您可以通过这种方式发送文件输入(仅通过序列化)。
这是你必须做的:
var data = new FormData();
jQuery.each(jQuery('#file')[0].files, function(i, file) {
data.append('file-'+i, file);
});
然后你可以通过ajax发送它们
firstnameInputValue = $('#firstnameInput').val();
jQuery.ajax({
url: 'php/upload.php',
data: {
file: data,
firstname: firstnameInputValue
},
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
alert(data);
}
});
在那里找到它:Sending multipart/formdata with jQuery.ajax
过去处理过这个问题。
关于javascript - $_FILES 为空且不包含任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40620354/
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我有一个选择多个文件的文件输入,如下所示: 当用户选择一个文件(或多个文件)时,我使用 Javascript 将 id 和类更新为“oldFile”,然后添加另一个文件输入,但使用 file2[]
我正在使用 PUT 方法在前端使用 dropzone.js 上传文件。然而,当我想处理文件时,Symfony 的 Request 对象和 $_FILES 数组都是空的。 我已经检查了 this hug
我正在使用 PUT 方法在前端使用 dropzone.js 上传文件。然而,当我想处理文件时,Symfony 的 Request 对象和 $_FILES 数组都是空的。 我已经检查了 this hug
这个问题已经有答案了: jQuery not posting all inputs of a form after the .append() (5 个回答) 已关闭 3 年前。 我目前有一个带有单个
我在使用 Alamofire 将文件上传到服务器时遇到了一些问题。 文件上传良好,但上传应出现的变量为空:FILES:array(0) {\n}\nPOST:array(0) {\n}\n 并且使用该
我正在尝试将文件上传到某个目录。该目录记录在数据库中。但是,代码无法读取 $_FILES 我每次尝试上传文件时都会得到空值。但其他输入数据都记录到数据库中。发生的情况是我无法在数据库中记录文件名,它只
我正在尝试将多个图像上传到 php 服务器,但由于某种原因,它对所有上传的图像使用第一个图像名称,保存到相同的图像名称。我希望它保存到源文件夹中的文件名中。像Banner1.jpg一样,Banner2
我正在尝试将图像存储到 mysql 数据库中,但在 ajax 页面中 $_FILE['textfield_Name']['temp_name'] 无法识别它。帮我解决这个问题。 这是我的文件页面代码
所以,我最近研究了如何使用 Blob 将文件上传到数据库。这是我找到的教程http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploadi
这个问题在这里已经有了答案: What does enctype='multipart/form-data' mean? (9 个回答) 关闭 7 年前。 我正在尝试创建一个脚本来上传 .mp3 文
好吧,有一点前言:我一直在致力于将拖放文件上传功能添加到名为 Moodle 的类(class)管理系统(特别是 2.0.1)中。该版本的Moodle使用YUI3框架,通过io-upload-ifram
这个问题已经有答案了: Sending multipart/formdata with jQuery.ajax (13 个回答) 已关闭 6 年前。 在描述我的问题之前,我确实在互联网和本网站上进行了
所以我正在为我妈妈开发一个网站,她想从她的相机上传照片,我首先用我在计算机上找到的一张普通图片测试了我的代码,该图片是在 photoshop CS6 和 $_FILES 数组中创建的没关系: arra
我整天都在为这个问题苦苦挣扎,厌倦了被困住。今天早上花了半个小时在我现在坚持使用的同一个应用程序上为个人资料图片做了一个不错的小自定义 uploader 。 这里的问题不是上传(我已经记下了),而是将
我正在尝试调试 $_FILES 数组的一个非常奇怪的问题。当我尝试上传文件时,仅设置了“名称”键,类型、tmp_name 等为空,并返回错误 #1。例如: Array ( [name] =>
当尝试访问$_FILES 数组时,PHP 返回错误 "Undefined index: picture". 在我的php.ini 文件中,File Uploads 是打开的,任何用户都可以在/tmp
这是我的 html 页面,其中包含表单: Dosya Adı:
我正在处理一个 PHP 上传脚本,在测试我的错误检查时,我试图上传一个 17MB 的 TIFF 文件。当我这样做时,$_FILES 数组是空的。该脚本可以很好地满足我需要它执行的操作,即上传 JPEG
我在用 PHP 上传多个文件时遇到一点问题, 我有这个 html 表单: 这是 upload.php : 当我发送文件时,它会显示: Array ( [myfile] =>
我是一名优秀的程序员,十分优秀!