savagenoob Posted May 22, 2009 Share Posted May 22, 2009 Customers that will be using my website will be using a certain program locally on their computers that saves as .dat files. Is it possible, to build a program that the customer could select the directory these .dat files are saved in, and php could import each file which contains client data using fopen - fread - and parsing? I have already been successful opening one of these files using fopen and fread, all the info is in tact. Link to comment https://forums.phpfreaks.com/topic/159211-fopen-fread-hypothetical-question/ Share on other sites More sharing options...
corbin Posted May 22, 2009 Share Posted May 22, 2009 Yes. You will of course have to know how to parse the data though. fread() just reads bytes. Link to comment https://forums.phpfreaks.com/topic/159211-fopen-fread-hypothetical-question/#findComment-839691 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 Thanks Corbin, Im pretty sure I can parse the data easily, each field is seperated by "". That is not my biggest obstacle, I dont know how to have the user select the directory and automatically cycle through each .dat file in the directory, any starting pointers for me ? Link to comment https://forums.phpfreaks.com/topic/159211-fopen-fread-hypothetical-question/#findComment-839696 Share on other sites More sharing options...
savagenoob Posted May 22, 2009 Author Share Posted May 22, 2009 How bout this... <?php // open the current directory $dhandle = opendir('.'); // define an array to hold the files $files = array(); if ($dhandle) { // loop through all of the files while (false !== ($fname = readdir($dhandle))) { // if the file is not this file, and does not start with a '.' or '..', // then store it for later display if (($fname != '.') && ($fname != '..') && ($fname != basename($_SERVER['PHP_SELF']))) { $files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname; } } // close the directory closedir($dhandle); } foreach( $files as $fname ) { $handle = fopen($fname, "r"); $contents_of_file = fread($handle, filesize($name)); //input parser code here //input insert into database code here } ?> Link to comment https://forums.phpfreaks.com/topic/159211-fopen-fread-hypothetical-question/#findComment-839704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.