Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Problem with reading the content of a text file

Codes here !

Moderators: macek, egami, gesf

Problem with reading the content of a text file

Postby polepole » Sun May 13, 2012 7:51 am

I'm trying to read the contents of a text file in to a csv file. This works with the code below when testing it locally. But it doesnt seem to work when the php pages are placed on another server.. The csv file is being made when executing but stays empty.

Code: Select all
$PatientNaam  = ($_POST["naam"] != "") ? $_POST["naam"]  : "Anoniem";
$donorfile = $_FILES['donorfile']['name'];
$patientfile = $_FILES['patientfile']['name'];   

$file = file($donorfile);

$count = count($file);

$fp = fopen('file1.csv', 'w');

$array = array();
//$i = 0;

 echo $file;
foreach ($file as $line) {
   echo " ".$line." ";
   $line = preg_replace('/(\s+)/',"\t",$line);   
   $line = str_replace(",","\t",$line);
   $line = preg_replace("/(\t)+$/",'',$line);
   echo " ";
   $array = explode("\t", $line);
      if(!fputcsv($fp, $array, ";")){
   echo "write error";
   fputcsv($fp, $array, ';');
//   $i++;


echo "$count";

The output is: 1

This is the echo of $count.
It doesn't seem to echo anything within the Foreach loop (the echo $line and error message)..

Hope someone can help.
Thanks in advance.
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 30, 2012 9:28 am

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.