嘿伙计们,我有以下几点:
session_start();
$seterror = 0;
function returnBack(){
header("Location:../memberinterface.php?getmsg=15");
exit;
}
function returnBackfile(){
header("Location:../memberinterface.php?getmsg=16");
exit;
}
if (!empty($_FILES['csvfile']['error'] ) )
{
$seterror = 1;
returnBack();
}
if (empty($_POST['firstname'])){
$seterror =1;
returnBack();
}
if (empty($_POST['lastname'])){
$seterrro =1;
returnBack();
}
if (empty($_POST['email'])){
$seterror =1;
returnBack();
}
if ($seterror !== 1){
$file = $_FILES['csvfile']['tmp_name'];
$handle = fopen($file , "r");
$fileop = fgetcsv($handle,0,"\t");
echo '<pre>'; var_dump($fileop); var_dump($_POST); echo '</pre>';
exit;
$fileop=array_map("strtoupper",array_map("trim",$fileop));
$firstname_index = array_search(strtoupper($_POST["firstname"]),$fileop);
if ($firstname_index===false){
returnBack();
}
$lastname_index = array_search(strtoupper($_POST["lastname"]),$fileop);
if ($lastname_index===false){
returnBack();
}
$email_index = array_search(strtoupper($_POST["email"]),$fileop);
if ($email_index===false){
returnBack();
}
//open file and store values
$j = 0;
while (($fileop=fgetcsv($handle,0,"\t")) !== false)
{
$fileop=array_map("trim",$fileop);
$firstname[$j] = $fileop[$firstname_index];
if (empty($firstname[$j])){
returnBackfile();
}
$lastname[$j] = $fileop[$lastname_index];
if (empty($lastname[$j])){
returnBackfile();
}
$email[$j] = $fileop[$email_index];
if (empty($email[$j])){
returnBackfile();
}
$j++;
}
//create sessions, send back to memberinterface.php and open table to display the results to delete
$_SESSION['CSVRfirstnames'] = $firstname;
$_SESSION['CSVRlastnames'] = $lastname;
$_SESSION['CSVRemails'] = $email;
header("Location:../memberinterface.php?RemoveCSV=1");
}
还有我在列中回显的部分:echo '<pre>'; var_dump($fileop); var_dump($_POST); echo '</pre>';
- 发生了一件奇怪的事情。
对于一些 CSV 文件,我得到了这个输出:
array(4) {
[0]=>
string(726) "PK!|l˜l [Content_Types].xml ¢( Ì”]KÃ0†ïÿCÉ4Ù&ˆÈº]øq©çˆÍé–&!'›Û¿÷4û@¤nzÓÐæœ÷}’4ïp¼jL¶„€ÚÙ‚õye`K§´ìmú”ß²£´Jg¡`k@6]^§k˜Q·Å‚Õ1ú;!°¬¡‘ÈK3•ŒôfÂËr.g ½Þ(`c[
6>@%&f+ú¼!"
[1]=>
string(71) "`e÷›ÂÖ«`Ò{£K‰T,úæ’o8u¦¬µÇ+Â`¢Ó¡ùÙ`Û÷B[´‚l"C|–
aˆ•.Ìß›óÃ"”®ªt"
[2]=>
string(951) "v€£ Ö±1<¼‘Úî¸ø§bi蟤]_>‘cðO8®ÿˆ#Òÿ"=$IæÈ`\À3¯v#z̹–Ôk”gøª}ˆƒîÑ$8”(Nß…]d´Ý¹'!QÃ>4º.ßÞ‘ÒètÃo·Ú¼S :¼EÊ×Ñ'ÿÿPK!µU0#õL_rels/.rels ¢( Œ’ÏNÃ0ÆïH¼CäûênH¡¥»LH»!TÀ$îµ£$@÷ö„‚JcÛÑöçÏ?[ÞîæiTb/Nú(A±3b{×jxŸV b"giÇŽaWÝÞl_x¤”›b×û¨²‹‹º”ü#b4Oñìr¥‘0QÊahÑ“¨eÜ”å=†¿P-<ÕÁj{ª>ú<ù²·4Mox/æ}b—NŒ@ž;ËvåCf©ÏÛ¨šBËIƒóœÓÉû"cž&Ú\Oôÿ¶8q"K‰ÐHàó<ߊs@ëë.Ÿh©ø½Î<⧄áMdøaÁÅT_ÿÿPK!Þ"
[3]=>
string(530) "(Ôxl/_rels/workbook.xml.rels ¢( ¼“ÏjÃ0ÆƒÑ}q’ne”:½ŒA¯[÷&QâÐÄ6–ö'o?“Cº@É.¡ƒ$ü}?Чýá§ïÄjU%)´¥«ZÛ(ø8½><ƒ Ö¶Ò³¨`@‚Cq·ÃNsüD¦õ$¢Š%†Ù襤Ò`¯)qmœÔ.ôšcéuyÖ
Ê
string(9) "Firstname"
["lastname"]=>
string(8) "lastname"
["email"]=>
string(5) "Email"
}
和其他 csv 文件,我得到了很好的组织:
array(3) {
[0]=>
string(9) "firstname"
[1]=>
string(8) "lastname"
[2]=>
string(5) "email"
[3]=>
}
array(3) {
["firstname"]=>
string(9) "Firstname"
["lastname"]=>
string(8) "lastname"
["email"]=>
string(5) "email"
}
现在我不知道为什么我会得到一些奇怪的符号,而且我不想要那些,所以如果你能帮助我,那就太好了!
大卫