javascript - 使用 PHP & Javascript 获取文件输入的空白值以发送表单
问题描述
我面临一个问题。使用 PHP 提交表单后,我得到了文件输入的空白值。我在下面解释我的代码。
<form action="" method="POST" enctype="multipart/form-data">
<div class="row form-group">
<label class="col-md-3 control-label text-left">Icon</label>
<div class="col-md-8 image-upload">
<label for="vcicon">
<img src="<?php if($ts->sett_img==''){ echo PT_TOURS_SLIDER_THUMB_UPLOAD.'blank.jpg'; }else{ echo $ts->sett_img; } ?>" style="cursor:pointer;width:auto; height:160px; border:1px #666 solid" id="preview_imgedit"/>
</label>
<input type="file" id="vciconedit" name="vciconedit" accept="image/*"/>
<div class="input-group bmargindiv1 col-md-12">
<label for="vcicon" >
<span style="color:#00F; font-style:italic; cursor:pointer"> Click here to upload Icon </span>
<input type="hidden" name="someIconedit" id="someIconedit" value="<?php echo $ts->sett_img; ?>" />
</label>
</div>
</div>
</div>
</form>
上面的部分是我的 HTML 表单,下面给出了 JavaScript 部分。
$('#vciconedit').change(function(){
readImageData(this);
})
function readImageData(imgData){
if (imgData.files && imgData.files[0]) {
var readerObj = new FileReader();
readerObj.onload = function (element) {
$('#preview_imgedit').attr('src', element.target.result);
$('#someIconedit').val('');
}
readerObj.readAsDataURL(imgData.files[0]);
}
}
<?php
print_r($_FILES);exit;
?>
当我在提交后打印文件值时,给出如下值。
Array ( [vciconedit] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
在这里,我需要在提交表单后从上面的数组中获取所有值。
解决方案
推荐阅读
- scheme - 如何将一个列表变成多个返回值?
- python - python检查登机时间-如果不是45分钟,则计算等待多长时间
- c# - 如何将具有唯一字段的两个不同对象列表合并到单独的列表中?
- latex - — 扫描使用 \@xdblarg 时文件结束。乳胶作品
- flutter - Flutter中如何改变appBar背景颜色以匹配不同tabView页面的背景颜色?
- python - 如何从 html for python 获取值
- javascript - Google Apps Script HTML 表单不会为海外用户提交
- node.js - 修改 mongoose 预验证钩子中的数据
- android - LinearLayout 中按钮前的图标
- c++ - SendInput 不发送我指定的确切像素数量