If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Unzip .csv before uploading

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-10, 21:53
Diesel Dud Diesel Dud is offline
Registered User
 
Join Date: Feb 2010
Location: Montreal, CA
Posts: 32
Unzip .csv before uploading

Hello,

I am familiar with the downloading of a csv from a url to insert into a mysql table.

I seem to be having difficulty now that the csv is zipped.
after doing:
a) $tempVar = file_get_contents($url);
b) $print = explode("\n",$tempVar);
c) $subPrint = explode (",",$print[$i]);

I obtain strange characters.

Can anyone suggest a solution?

Thanks
Reply With Quote
  #2 (permalink)  
Old 12-06-10, 11:15
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
You need to unzip the csv, otherwise you're just going to end up with binary gobbledy-gook.

The zip extension will probably be of use.
Reply With Quote
  #3 (permalink)  
Old 12-15-10, 12:31
Diesel Dud Diesel Dud is offline
Registered User
 
Join Date: Feb 2010
Location: Montreal, CA
Posts: 32
Quote:
Originally Posted by futurity View Post
You need to unzip the csv, otherwise you're just going to end up with binary gobbledy-gook.

The zip extension will probably be of use.

Thanks for the prompt response.
I glanced at it but only got around to the programing just now.

Do you have a practical example of how I can extract a csv from a zip?
I'm not sure the examples here PHP: Examples - Manual are what I need.

Should I be using the ExtractTo method? PHP: ZipArchive::extractTo - Manual
Is this necessary? My preference is to simply "read" the csv so i can dump each line into a table.

Thanks.
Reply With Quote
  #4 (permalink)  
Old 12-16-10, 10:48
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
I've not personally used this extension, nor handled zip file uploads, so you'll have to do some experimentation on your own.

The zip functions seem easier and more intuitive to use, not to mention the class-based API doesn't seem to offer any way to directly read an archive without first unzipping it. But I can't tell whether or not the functions are an old and/or depreciated API.

Anyway, I imagine you'd do something like:
PHP Code:
$dir zip_open('file');
$entry zip_read($dir);
$clear zip_entry_read($entry); 
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
Pingbacks are On
Refbacks are On