473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
/var/www/html/home/accounts/trackfiles");
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'".
"(".$fields.")";
$result = @mysql_query($sql, $dbconn) or die("Couldn't query DB: " .
mysql_error());

Jul 17 '05 #1
0 1539

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: xrongor | last post by:
hi. i need a simple, hopefully free html editor that besides the standard features has the following properties: allows frames. and will allow me to create a "directory" based on data...
6
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling...
0
by: frankkirchner | last post by:
There has to be a way to get an image into the XSLT transormation process so that it shows up on a Formatted Excel Spreadsheet. When saving an Excel spreadsheet to XML format - you lose the image...
7
by: Mark Knochen | last post by:
Hello, i have a php-script with a mysql_query ... $insert = mysql_query("INSERT INTO $table (textID,redaktion) VALUES ('$_POST','$row_startseiten')"); I get no mysql_error, if i copy the...
3
by: davnao | last post by:
I would like to open an existing workbook, select a work sheet and insert multiple rows at the top of the spreadsheet. Have the following code, but unsure of proper command & syntax for Insert row,...
5
by: Sport Girl | last post by:
Hi again my great online assistants, just would like to say that i'm testing the script under unix , and after researches on the internet, i have realised that to resolve 500 Internal Server Error,...
3
by: JFKJr | last post by:
Hello everyone, I am trying to insert a picture in an excel spreadsheet cell using Access VBA. The following excel VBA code is working perfectly fine and I am able to insert picture in "A1" cell....
2
by: franc sutherland | last post by:
Hello, I am using Access 2003. Is it possible to use string variables in the INSERT INTO statement? I am using the INSERT INTO statement to add a long list of contacts to a group by looping...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.