var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Unzip .csv before uploading
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.
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?
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.
Originally Posted by
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.
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:
$dir = zip_open ( 'file' );
$entry = zip_read ( $dir );
$clear = zip_entry_read ( $entry );