Hello,
I am getting an unexpected errror when trying to create a new file using fwrite. I am creating an html page based from a list of words from a text file. Everything should work fine, but for some reason only the last file gets created successfully. all others put an unneccesary white space at the end of the file name which creates a bad file. eg... page .html instead of page.html . This causes two seperate files to be written as page and .html. The weird thing is that the last word on the list is built successfully as lastword.html. All other divide the name up into two corrupt pages of pagename and .html.
Here is my code
PHP Code:
<?
$word=$_POST[word];
$saveto=$_POST[saveto];
if (!file_exists($saveto)) {
mkdir ($saveto, 0777);
}
$readfile = file(lists/words-$word.file);
for ($k=0; $k<=count($readfile)-1; $k++) {
$fields= $readfile[$k];
$safefile= str_replace( ,_, $fields);
$keynamed=$saveto/$fields.html;
$string=some text ;
$page = fopen($keynamed,w);
fwrite($page,$string);
fclose($page);
echo $keynamed Successfully Created<br>;
}
echo All Files saved in: $saveto;
?>
If anyone can offer me any assistance, I will be greatful. I am about to throw my new monitor through my window
Hello,
I am getting an unexpected errror when trying to create a new file using fwrite. I am creating an html page based from a list of words from a text file. Everything should work fine, but for some reason only the last file gets created successfully. all others put an unneccesary white space at the end of the file name which creates a bad file. eg... page .html instead of page.html . This causes two seperate files to be written as page and .html. The weird thing is that the last word on the list is built successfully as lastword.html. All other divide the name up into two corrupt pages of pagename and .html.
Here is my code
PHP Code:
<?
$word=$_POST[word];
$saveto=$_POST[saveto];
if (!file_exists($saveto)) {
mkdir ($saveto, 0777);
}
$readfile = file(lists/words-$word.file);
for ($k=0; $k<=count($readfile)-1; $k++) {
$fields= $readfile[$k];
$safefile= str_replace( ,_, $fields);
$keynamed=$saveto/$fields.html;
$string=some text ;
$page = fopen($keynamed,w);
fwrite($page,$string);
fclose($page);
echo $keynamed Successfully Created<br>;
}
echo All Files saved in: $saveto;
?>
If anyone can offer me any assistance, I will be greatful. I am about to throw my new monitor through my window
|
|
Search Webmaster Help and Solution
fwrite unexpected errorsRelated ItemsQuery failed: connection to localhost:3354 failed (errno=111, msg=Connection refused). |
