470,602 Members | 1,447 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

Can't insert spreadsheet edited in Linux with PHP script

I have no idea if this is a Linux issue or PHP. Looking for clues here.

I have a PHP script which I use to upload a CSV spreadsheet into a
mySQL database. (The script follows here in a sec.)
I was using WindowsXP and MS Excel to take these sheets, edit it if
needed, and save it in text based CSV. Then use the PHP script to
upload it and insert into the DB.

Now I've eschewed Windows and am using Fedora Core 3. I've tried doing
the same thing I always do, but with Open Office, and I've tried with
Gnumeric and KSpread, and I save it as CSV, but for some reason the PHP
script no longer properly uploads. It acts as if it's an empty file.

I don't think it's file folder or structure issue, because I'll edit it
in one of the three programs and then copy it to a WindowsXP machine
and upload it with the script and I get the same problem.

If I edit it and save it in CSV in MS Excel and then open it in
Notepad, I get proper lines with proper carriage returns in the right
places. If I edit it in a Linux program and then open it in an ASCII
editor it also looks just fine, but if I open it in Windows Notepad,
there carriage returns are in odd places and there's little squares
indicating a hidden or binary character here and there. Weird!

Any ideas what's going on here?
a) Is there anything I can do in one of the Linux programs (preferably
Open Office Calc) to save it properly in ASCII only CSV with proper
\r\n carriage returns? or
b) Anything I can do in the PHP to compensate for whatever the Linux
programs are doing to the CSV?

Thanks for any help!!
Here's the PHP:

$uploaddir = '/var/www/html/home/accounts/trackfiles/';
$upfilename = $_FILES['csvfile']['name'];
$uploadfile = $uploaddir . $upfilename;
move_uploaded_file($_FILES['csvfile']['tmp_name'], $uploadfile);
$change_perm = escapeshellcmd("/bin/chmod a+rw -R
exec("$change_perm 2>&1", $output);

$sql = "LOAD DATA INFILE '".$uploadfile."' INTO TABLE `".$tbl."` FIELDS
$result = @mysql_query($sql, $dbconn) or die("Couldn't query DB: " .

Jul 17 '05 #1
0 1414

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by xrongor | last post: by
6 posts views Thread by Daniel | last post: by
7 posts views Thread by Mark Knochen | last post: by
2 posts views Thread by franc sutherland | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.