- Joined
- Feb 28, 2010
- Messages
- 2
- Reaction score
- 0
- Points
- 1
- Your Mac's Specs
- 2.53 GHz Intel MacBook Pro 13.3" 4GB
I have a racing website that I'm building and I'm using a CSV template to load the result and points from the night. I have the template setup and save them as CSV's and load them. The problem is that if the CSV is created on a Windows machine it gives me an error that says the CSV file is not of the correct type. But if I take the exact same file and save a CSV on my Mac using MS Excel 2011 it works without a problem. I've even done it with Numbers and it worked.
The function I'm using to check is crude (I've only been doing web work for a little over a year), but I'm getting hung up in the spot I have highlighted as red.
If anyone could help me, I'd greatly appreciate it.
Thanks.
<h1>Uploading file</h1>
<?php
$userfile = $HTTP_POST_FILES['userfile'] ['tmp_name'];
$userfileName = $HTTP_POST_FILES['userfile']['name'];
$userfileSize = $HTTP_POST_FILES['userfile']['size'];
$userfileType = $HTTP_POST_FILES['userfile']['type'];
$userfileError = $HTTP_POST_FILES['userfile']['error'];
$series= $HTTP_POST_VARS['series'];
echo $series;
if($userfileError > 0) {
echo 'Problem: ';
switch ($userfileError) {
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
//does file have right MIME type
if ($userfileType != 'text/csv')
{
echo 'Problem: file is not plain text';
exit;
}
// put file in correct place
$upfile = 'uploads/'.$userfileName;
if (is_uploaded_file($userfile)) {
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename:'.$userfileName;
exit;
}
echo 'File uploaded successfully<br /><br />';
// reformat the file contents
$fp = fopen($upfile, 'r');
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);
$contents = strip_tags ($contents);
$fp = fopen($upfile, 'w');
fwrite($fp, $contents);
fclose($fp);
echo 'Preview of uploaded file contents: <br /><hr />';
if (($handle = fopen($upfile, 'r')) !== false) {
while(($row = fgetcsv($handle, 100000, ",")) !== false){
$query = join(",", $row)."<br/>";
echo $query;
}
}
echo '<br /><hr />';
csv_file_to_mysql_table($upfile, $series);
}
?>
The function I'm using to check is crude (I've only been doing web work for a little over a year), but I'm getting hung up in the spot I have highlighted as red.
If anyone could help me, I'd greatly appreciate it.
Thanks.
<h1>Uploading file</h1>
<?php
$userfile = $HTTP_POST_FILES['userfile'] ['tmp_name'];
$userfileName = $HTTP_POST_FILES['userfile']['name'];
$userfileSize = $HTTP_POST_FILES['userfile']['size'];
$userfileType = $HTTP_POST_FILES['userfile']['type'];
$userfileError = $HTTP_POST_FILES['userfile']['error'];
$series= $HTTP_POST_VARS['series'];
echo $series;
if($userfileError > 0) {
echo 'Problem: ';
switch ($userfileError) {
case 1: echo 'File exceeded upload_max_filesize'; break;
case 2: echo 'File exceeded max_file_size'; break;
case 3: echo 'File only partially uploaded'; break;
case 4: echo 'No file uploaded'; break;
}
exit;
}
//does file have right MIME type
if ($userfileType != 'text/csv')
{
echo 'Problem: file is not plain text';
exit;
}
// put file in correct place
$upfile = 'uploads/'.$userfileName;
if (is_uploaded_file($userfile)) {
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
}
}
else
{
echo 'Problem: Possible file upload attack. Filename:'.$userfileName;
exit;
}
echo 'File uploaded successfully<br /><br />';
// reformat the file contents
$fp = fopen($upfile, 'r');
$contents = fread ($fp, filesize ($upfile));
fclose ($fp);
$contents = strip_tags ($contents);
$fp = fopen($upfile, 'w');
fwrite($fp, $contents);
fclose($fp);
echo 'Preview of uploaded file contents: <br /><hr />';
if (($handle = fopen($upfile, 'r')) !== false) {
while(($row = fgetcsv($handle, 100000, ",")) !== false){
$query = join(",", $row)."<br/>";
echo $query;
}
}
echo '<br /><hr />';
csv_file_to_mysql_table($upfile, $series);
}
?>