troubleshooting Question

Code doesn't convert and save the file

Avatar of MICHAEL HOGGATT
MICHAEL HOGGATT asked on
PHPWindows 10
4 Comments1 Solution38 ViewsLast Modified:
The attached code was written for me by one of the Experts a couple of years ago and unfortunately I don't remember his name.
The code worked in Windows 7 but now it does not work in Windows 10.
The code does run but not completely.

This code searches through a .txt file for periods and when it finds one it executes a carriage return so that each sentence is on its own line.
The code stores the converted text in a file called 'uploads' in the wwwroot folder.
Probably is looking at a wrong directory or something simple like that.

index.html
<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

uploads.php
<?php
// The source file
$inFile = "1corinthians7.txt";
var_dump(file_exists($inFile));

// The file we'll write with the line breaks
$outFile = "converted_lines.txt";

// Open the files
$fpIn = fopen($inFile, "r");
$fpOut = fopen($outFile, "w");

// Loop through the source file, 1k at a time
while(!feof($fpIn))
{
  $chunk = fread($fpIn, 1024);

  // Replace every . with a . and a line break afterwards and write that to the out file
  fwrite($fpOut, str_replace(".",".\n",$chunk));
}

// Close the files
fclose($fpIn);
fclose($fpOut);
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros