Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 15th, 2009, 08:17 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CSV Import library for Products

Hi, i have problems with this operation. After the file is chosen and imported, we get on .../admin/products/import - But there is nothing displayed There are no errors - simply pure screen
Any idea?
Reply With Quote
  #2 (permalink)  
Old March 16th, 2009, 09:59 AM
Wrox Author
 
Join Date: May 2008
Location: Austin, TX, USA.
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Can you provide more details? Perhaps a code dump of where you are going? or maybe a look at the data structure you are trying to pull in?
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
Reply With Quote
  #3 (permalink)  
Old March 20th, 2009, 04:56 PM
Registered User
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same issue, but several things I've discovered:

If your following the book
Code:
function importCsv()
should read when you load the library:

Code:
$this->load->library('CSVReader);
not

Code:
$this->load->library('CSVreader');
Then if you look in the CSVReader class you'll see the method is called parse_file not parseFile so the return statment should be

Code:
return $this->csvreader->parse_file($path)
not

Code:
return $this->csvreader->parseFile($path)
Reply With Quote
  #4 (permalink)  
Old March 21st, 2009, 10:35 AM
Wrox Author
 
Join Date: May 2008
Location: Austin, TX, USA.
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default Here's what I have

In the code for CSVReader, I have:

Code:
class CSVReader {
    
    var $fields;            /** columns names retrieved after parsing */
    var $separator = ',';    /** separator used to explode each line */
    
 
    function parseText($p_Text) {
        $lines = explode("\n", $p_Text);
        return $this->parseLines($lines);
    }
    

    function parseFile($p_Filepath) {
        $lines = file($p_Filepath);
        return $this->parseLines($lines);
    }
    
 
    function parseLines($p_CSVLines) {    
        $content = FALSE;
        foreach( $p_CSVLines as $line_num => $line ) {
            if( $line != '' ) { // skip empty lines
                $elements = split($this->separator, $line);
                
                if( !is_array($content) ) { // the first line contains fields names
                    $this->_fields = $elements;
                    $content = array();
                } else {
                    $item = array();
                    foreach( $this->_fields as $id => $field ) {
                        $item[$field] = $elements[$id];
                    }
                    $content[] = $item;
                }
            }
        }
        return $content;
    }
}
There's a parseFile() method in the class. Now here's the function in the MOrders model:

Code:
 function importCsv(){
 	
	$config['upload_path'] = './csv/';
	$config['allowed_types'] = 'csv';
	$config['max_size'] = '2000';
	$config['remove_spaces'] = true;
	$config['overwrite'] = true;
	$this->load->library('upload', $config);
  	$this->load->library('CSVReader'); 
  	
	if(!$this->upload->do_upload('csvfile')){
		$this->upload->display_errors();
		exit();
	}
	$csv = $this->upload->data();
	$path = $csv['full_path'];
	
	return $this->csvreader->parseFile($path);
 }
In the model, I call the library properly "CSVReader" and the method too "parseFile($path)".

In the book, on page 199, I call the library improperly as "CSVreader". I'm not sure how it happened, but it happened. Sorry about that -- the code is correct, the example has the typo.

Now I'm wondering where the parse_file() thing came from, I can't find it anywhere.
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
Reply With Quote
  #5 (permalink)  
Old April 28th, 2009, 06:26 AM
Registered User
 
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem, after hours of bugs fixing and googling , i found this :
http://codeigniter.com/forums/viewthread/86033/#554404

I think the problem related to bug in FF3, because I got the following error :
Array( [error] => The filetype you are attempting to upload is not allowed.)
and parsing the upload data, i get :

Array( [dataup] => Array ( [file_name] => products_export.csv [file_type] => \"text/x-comma-separated-values\" [file_path] => D:/wwwroot/CodeIgniter/claudia/tmp/ [full_path] => D:/wwwroot/CodeIgniter/claudia/tmp/products_export.csv [raw_name] => products_export [orig_name] => [file_ext] => .csv [file_size] => 2.96 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ))

Notice in : [file_type] => \"text/x-comma-separated-values\"

Try to test your code in internet explorer..
thx..

www.paulussetyo.com
Reply With Quote
  #6 (permalink)  
Old April 28th, 2009, 06:30 AM
Registered User
 
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by myerman View Post
In the code for CSVReader, I have:
Now I'm wondering where the parse_file() thing came from, I can't find it anywhere.
If you download the latest CSVReader, the function should be : parse_file() not parsefile()

Thx
Reply With Quote
  #7 (permalink)  
Old June 16th, 2009, 07:12 PM
Authorized User
Points: 133, Level: 2
Points: 133, Level: 2 Points: 133, Level: 2 Points: 133, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think the empty page error due to that no "csv" folder was created in the CI root. That "csv" folder we need to create by ourselves, it is not included in the download. And you need to make that folder writable.

Last edited by blackhorse66; June 18th, 2009 at 12:47 AM.
Reply With Quote
  #8 (permalink)  
Old August 5th, 2009, 09:55 PM
Registered User
 
Join Date: Jan 2004
Location: Tawau, Sbh, Malaysia.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using FF 3.5.2, I also having the same problem, which is FF display
"The filetype you are attempting to upload is not allowed"

What I done is in config/mimes.php
I added one more array value, '\"text/x-comma-separated-values\"'

Code:
'csv'    =>    array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', '\"text/x-comma-separated-values\"'),
Then its work in FF 3.5.2, hope my reply can help you all.
__________________
Hi, Everyone!!!
Reply With Quote
Reply


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Import CSV files to Database in C# prasanna.nadgir C# 2 September 4th, 2007 11:03 AM
Import from CSV to MSDE tables dhol SQL Server DTS 14 June 5th, 2007 04:53 AM
Import data to CSV itHighway Classic ASP Basics 0 September 15th, 2006 10:31 AM
Import data in CSV file itHighway Classic ASP Professional 0 September 15th, 2006 10:29 AM
CSV and Excel sheet import itHighway Classic ASP Professional 0 August 5th, 2006 08:25 AM



All times are GMT -4. The time now is 09:35 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.