Solved

uploads contents of csv but not excel

Posted on 2008-10-01
1
247 Views
Last Modified: 2013-12-12
hello all
my code for csv works fine but when I try to upload excel, it doesn't work. How do I change it so I can upload excel files

Thanks
<?php 
 
 

require_once('connect_info.php');

// yourfile.csv must be in the same directory as this php file 

$handle = fopen ("upload8\\".$_SESSION['filename'],"r+"); 
 

while ($data = fgetcsv ($handle, 3000, ",")) { 

$atsign = "@no.mail"; 

$gtoken = mysql_real_escape_string ($data[0]);
 

$dedupe = mysql_query("select token from users where token = '".$gtoken."'") or die ("tokens not selected : " .mysql_error());

$derow = mysql_num_rows($dedupe);

if($derow == 0) { 

$query = "insert into users (token) values ('".$gtoken."')";

$result = mysql_query($query) or die("Invalid query: <BR>" . mysql_error().__LINE__ ."<BR>"."Source code ". __FILE__); 

}
 

echo "upload8\update.csv";
 

} 
 

echo "Tokens inserted"; 

//mysql_close($link); 

fclose ($handle); 

header("location: admin.php");

exit;

?>

Open in new window

0
Comment
Question by:syedasimmeesaq
1 Comment
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 22617344
Hello syedasimmeesaq

excel creates binary files, you probably know, and without creating and Excel object (or equivalent) you cannot treat it as text (csv) file.

if you mean csv created by Excel, it surround cell contents with double quotes (") when there are spaces in. You've to experiment saving one cell with different values and parse them with your script.

HTH

I
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now