Hi:
I am relatively new to Php and I am trying to understand how to successfully upload files. Thus far I've managed to write code that uploads text files without problem. However, when I try to upload non-text files I run into problems. I am trying to upload a .vcf (vCard) file so I can parse it and dump the result into a MySQL database.
When I try to upload this type of file I get major problems with the content. For some reason the file name and a bunch of weird characters are appended to the beginning of the file. Then when I try to use regular expressions on the contents they won't work. I think that the problem may be with both the system I am using (Macintosh OS X 10.2.1) and with mime-type being application/x-macbinary.
The code I am using looks like this:
form code:
<?
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>";
?>
process code:
if($import == "import"){
if( !copy($userfile, $upfile)){
echo "Problem: Could not move file into directory";
exit;
}
$upfile = "uploads/".$userfile_name;
$fp = fopen($upfile, "rb");
$contents = fread($fp, filesize($upfile));
fclose($fp);
$fp = fopen($upfile, "w");
fwrite($fp, $contents);
fclose($fp);
}
If no one has any ideas about how to help me with this I would appreciate it if you could point me to a good file upload/download tutorial.