Hi:
I am trying to upload a .vcf file, split the various datafields into an array at the colons and semi-colons and dump the datafields into a MySQL database. I am having trouble with the file handling. I can upload the file fine (I'm using a standard html form) but I try to write out the file gets written out wrong. A bunch of information gets appended to the beginning of the file.
I think that the problem is with the file type but I am not certain.
The code I'm using looks like this:
if($import == "import"){
if ($userfile == "none"){
echo "Problem: no file uploaded";
exit;
}
if ($userfile_size==0){
echo "Problem: uploaded file is of zero length";
exit;
}
# if($userfile_type != "text/plain"){
# echo "Problem: file is not plain text";
# exit;
# }
if(!is_uploaded_file($userfile)){
echo "Problem: possible file upload attack";
exit;
}
$upfile = "uploads/".$userfile_name;
if( !copy($userfile, $upfile)){
echo "Problem: Could not move file into directory";
exit;
}
echo $userfile_name." file uploaded successfully<br><br>";
$fp = fopen($upfile, "rb");
$contents = fread($fp, filesize($upfile));
fclose($fp);
# $contents = strip_tags($contents);
$fp = fopen($upfile, "w");
fwrite($fp, $contents);
fclose($fp);
$fp = fopen($upfile, "r");
}
echo "<form enctype=\"multipart/form-data\" action=\"import.php\" method=post>Select File to Import <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000\"><input name=\"userfile\" type=\"file\">   <input type=\"submit\" name=\"import\" value=\"import\"></form>";
The uploaded file should look like:
BEGIN:vCard
VERSION:2.1
FN:Testies Testing
N:Testing;Testies
ADD:2898;fdjgdsgkh;hell;indiana;78908;usa
TEL;WORK:111.1111.1111
TEL;HOME:hfgkd
TEL;CELL:fdhgkds
TEL;FAX:dfkjs
EMAIL;INTERNET:test@test.com
TITLE:Something
ORG😮ff
X-CUSTOM1:dhkd
X-CUSTOM2:dfhs
X-CUSTOM3:dgh
X-CUSTOM4:dfg
END:vCard
But instead it looks like: