I think it is to do with the way the data is held
to upload the data from the local machine to the array $datlines
if( !isset($_POST['submit'])) { ?>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Ped file: <input name="pedfile" type="file" /><br />
Dat file: <input name="datfile" type="file" /><br />
Smp file: <input name="smpfile" type="file" /><br />
<input type="submit" name="submit" value="Upload Files" />
</form>
<?php }
else {
$uploaddir = './'; // same folder as this file set permission to 0777
$pedupload = $uploaddir . basename($_FILES['pedfile']['name']);
$datupload = $uploaddir . basename($_FILES['datfile']['name']);
$smpupload = $uploaddir . basename($_FILES['smpfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['pedfile']['tmp_name'], $pedupload) &&
substr($_FILES['pedfile']['name'],-4) == ".ped") {
echo "Ped file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
if (move_uploaded_file($_FILES['datfile']['tmp_name'], $datupload)&&
substr($_FILES['datfile']['name'],-4) == ".dat") {
echo "Dat file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
if (move_uploaded_file($_FILES['smpfile']['tmp_name'], $smpupload)&&
substr($_FILES['smpfile']['name'],-4) == ".smp") {
echo "Smp file is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
$pedlines = file($pedupload);
$datlines = file($datupload);
$smplines = file($smpupload);
therefore I have been suplimeneting your code with
<?php
echo "preg_match_all and preg_replace<br />";
$regex = "|#[^\n]+|";
$datlines_implode = implode(" " , $datlines);
preg_match_all($regex, $datlines_implode, $output);
$output = preg_replace("|#[\x20]|", "", $output[0]);
echo '<pre>';
print_r($output);
echo '<pre>';
?>
i think that the array is not holding the line breaks when it is uploaded and transefered around.
Any suggestions?