Jump to content

fopen - fread hypothetical question


savagenoob

Recommended Posts

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

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 ?  ;)

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
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.