Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
December 22, 2004, 2:55 pm
rate this thread
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;
$change_perm = escapeshellcmd("/bin/chmod a+rw -R
exec("$change_perm 2>&1", $output);
// INSERT SPREADSHEET DATA INTO DATABASE
$sql = "LOAD DATA INFILE '".$uploadfile."' INTO TABLE `".$tbl."` FIELDS
TERMINATED BY ','".
"OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'".
$result = @mysql_query($sql, $dbconn) or die("Couldn't query DB: " .
Re: Can't insert spreadsheet edited in Linux with PHP script
On 22 Dec 2004 08:55:12 -0800, email@example.com
If the little squares are in places other than the ends of lines, it
might be a locale problem, i.e. the file might be getting improperly
converted to or from UTF-8.
"Cow fault??? Have you progressed from BSD to BSE?"
cowsay -b "Prepare to be assimoolated! "