New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
Web Design and Hosting Creating sites, scripting, and hosting discussions.

Mac CSV vs. Windows CSV


Post Reply New Thread Subscribe

 
Thread Tools
snowman2025

 
Member Since: Feb 28, 2010
Posts: 2
snowman2025 is on a distinguished road
Mac Specs: 2.53 GHz Intel MacBook Pro 13.3" 4GB

snowman2025 is offline
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);
}
?>
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
Out of curiosity, try running dos2unix against it, then try importing it. Windows and *nix have completely different line formats in text files.

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
snowman2025

 
Member Since: Feb 28, 2010
Posts: 2
snowman2025 is on a distinguished road
Mac Specs: 2.53 GHz Intel MacBook Pro 13.3" 4GB

snowman2025 is offline
I don't even have to run the dos2unix against the file. As soon as I move the file created in windows my MBP it uploads just fine.

Unless you mean for me to run that on my Windows machine.
QUOTE Thanks

Post Reply New Thread Subscribe


« AFP and Internet sharing | Sending proper email headers »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
OS 10.7 Lion feature/rumour roundup the8thark Apple Rumors and Reports 44 08-17-2011 02:03 PM
P.C. user on a MAC, help dispel my hatred kdubbie Switcher Hangout 20 05-10-2011 06:23 PM
Switching soon with a Mac Mini from Linux and Windows walkerj Switcher Hangout 7 02-14-2005 02:23 PM
Mac Users Get More ISP Choices schweb Apple Rumors and Reports 1 03-06-2003 10:57 AM

All times are GMT -4. The time now is 02:24 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?