我试着以blob格式转换图像数组并发送到脚本php来处理数据但是blob数组没有正确发送,我不知道为什么。 我在html中的输入是:
$UserArray = Get-Content 'C:\Temp\Users.txt'
$GroupArray = Get-Content 'C:\Temp\Groups.txt'
$OutputFile = 'C:\Temp\Something.csv'
# Setting up a hashtable for later use
$UserHash = New-Object -TypeName System.Collections.Hashtable
# Outer loop to add users and membership to UserHash
$UserArray | ForEach-Object{
$UserInfo = Get-ADUser $_ -Properties MemberOf
# Strips the LPAP syntax to just the SAMAccountName of the group
$Memberships = $UserInfo.MemberOf | ForEach-Object{
($_.Split(',')[0]).replace('CN=','')
}
#Adding the User=Membership pair to the Hash
$UserHash.Add($_,$Memberships)
}
# Outer loop to create an object per user
$Results = $UserArray | ForEach-Object{
# First create a simple object
$User = New-Object -TypeName PSCustomObject -Property @{
Name = $_
}
# Dynamically add members to the object, based on the $GroupArray
$GroupArray | ForEach-Object {
#Checking $UserHash to see if group shows up in user's membership list
$UserIsMember = $UserHash.($User.Name) -contains $_
#Adding property to object, and value
$User | Add-Member -MemberType NoteProperty -Name $_ -Value $UserIsMember
}
#Returning the object to the variable
Return $User
}
#Convert the objects to a CSV, then output them
$Results | ConvertTo-CSV -NoTypeInformation | Out-File $OutputFile
我在javascript中的脚本是这样的:
<div class="form-group">
<input id="imagen" onchange="send()" type="file" name="imgs" multiple="true" class="form-control required" >
</div>
我正在尝试通过ajax调用将数组blob发送到脚本php:
<script>
var y='#imagen';
var z;
var blobs;
function send(){
x=trans(y);
};
function trans(v) {
var file = document.querySelector(v).files;
for (i = 0; i < file.length; i++) {
var reader = new FileReader();
reader.readAsDataURL(file[i]);
reader.onloadend = function () {
blobs[i]=reader.result;
}
}
console.log(blobs.length);
}
</script>
所以,我的问题是数组没有正确发送。求助。
答案 0 :(得分:0)
您正在联接data URI
,而不是Blob
s。
如果要求实际上是发布串联data URI
的字符串化数组,则可以使用立即调用的函数表达式。 FileReader
loadend
事件异步返回结果。您可以将i
传递给IIFE以在i
循环中保留for
引用
function trans(v) {
var file = document.querySelector(v).files;
for (i = 0; i < file.length; i++) {
(function(curr) {
var reader = new FileReader();
reader.readAsDataURL(file[curr]);
reader.onloadend = function () {
blobs[curr]=reader.result;
}
})(i);
}
console.log(blobs.length);
}