C# doesn't detect text file that was edited with PHP

Asked
Active3 hr before
Viewed126 times

6 Answers

doesn
90%

Now I made a C# application with TAPI3 to call the number in that text file. I use a FileSystemWatcher (watcher) to check the folder where php saves the text file so it makes the call everytime the file gets updated.,The following code checks which user is selected so it watches the folder of that user for the text file.,I have a PHP website on a Linux server. I made a button next to the phone numbers on the site that writes a text file on the server with that number. The following code works.,When the text file changes the following code will execute.

I have a PHP website on a Linux server. I made a button next to the phone numbers on the site that writes a text file on the server with that number. The following code works.

$file = './gebruikers/'.$naam.
'/nummer.txt';
$write = $_POST['num'];
file_put_contents($file, $write);
load more v
88%

However: You should care about the fact that a file's modification time will be changed if you use touch for files which already exists.,This will just create an empty file having the current time as creation time. The advantage over fopen is that you don't have to close the file., If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a). – Skyfish Feb 14 at 16:23 , Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers

Try using:

$fh = fopen($newfile, 'w') or die("Can't create file");
load more v
72%

A better method to open files is with the fopen() function. This function gives you more options than the readfile() function.,We will use the text file, "webdictionary.txt", during the lessons:,The fclose() function is used to close an open file.,The fread() function reads from an open file.

$myfile = fopen("webdict.txt", "r");
while (!($myfile)) {
   echo($myfile);
}
65%

file_get_contents() - Reads entire file into a string, file_​get_​contents ,fopen() - Opens file or URL, file_​put_​contents

load more v
75%

The Explorer is great for navigating between files when you are exploring a project. However, when you are working on a task, you will find yourself quickly jumping between the same set of files. VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings.,If the current file type has language support for symbols, you will see the current symbol path and a dropdown of other symbols at the same level and below.,If you open a file that has errors or warnings, they will be rendered inline with the text and in the overview ruler.,Selecting a breadcrumb in the path displays a dropdown with that level's siblings so you can quickly navigate to other folders and files.

You can use workbench.colorCustomizations to override these theme-contributed colors in your settings:

"workbench.colorCustomizations": {
   "editorBracketHighlight.foreground1": "#FFD700",
   "editorBracketHighlight.foreground2": "#DA70D6",
   "editorBracketHighlight.foreground3": "#179fff",
},
load more v
40%

“$file_name” is the path and name of the file to be checked, The code below uses file_exists function to determine if the file my_settings.txt exists., “$file_name” is the name of the file to be opened, “$file” specifies the file path and name of the file to be copied.

The file_exist function has the following syntax.

< ? php
file_exists($filename); ?
>

The code below uses file_exists function to determine if the file my_settings.txt exists.

< ? php
if (file_exists('my_settings.txt')) {
   echo 'file found!';
} else {
   echo 'my_settings.txt does not exist';
} ?
>

The fopen function is used to open files. It has the following syntax

< ? php
fopen($file_name, $mode, $use_include_path, $context); ?
>

It has the following syntax

< ? php
fwrite($handle, $string, $length); ?
>

It has the following syntax.

< ? php
fclose($handle); ?
>
< ? php

$fh = fopen("my_settings.txt", 'w')

or

die("Failed to create file"); ? >
< ? php

fclose($fh);

?
>
< ? php

$fh = fopen("my_settings.txt", 'w') or die("Failed to create file");

$text = << < _END

localhost;
root;
pwd1234;
my_database

_END;

fwrite($fh, $text) or die("Could not write to file");

fclose($fh);

echo "File 'my_settings.txt' written successfully"; ? >

The code below read_my_settings.php implements the above example.

< ? php
$fh = fopen("my_settings.txt", 'r') or die("File does not exist or you lack permission to open it");
$line = fgets($fh);
echo $line;
fclose($fh); ?
>

The code below illustrates the implementation

< ? php
copy('my_settings.txt', 'my_settings_backup.txt') or die("Could not copy file");
echo "File successfully copied to 'my_settings_backup.txt'"; ?
>

The unlink function is used to delete the file. The code below illustrates the implementation.

< ? php
if (!unlink('my_settings_backup.txt')) {
   echo "Could not delete file";
} else {
   echo "File 'my_settings_backup.txt' successfully deleted";
} ?
>

The difference between file_get_contents and fgets is that file_get_contents returns the file data as a string while fgets reads the file line by line.

<?php
echo "<pre>"; // Enables display of line feeds
echo file_get_contents("my_settings.txt");
echo "</pre>"; // Terminates pre tag
?>
load more v

Other "doesn-undefined" queries related to "C# doesn't detect text file that was edited with PHP"