[PHP] Problemen met schrijven van bestand. [OPGELOST]
Godlord - 17/01/2007 16:02 (laatste wijziging 17/01/2007 19:42)
PHP gevorderde
Ik heb problemen met het schrijven van een bestand in PHP. Ik wil dus bv. een .html bestand of .php bestand laten schrijven door een PHP bestand maarja ik heb problemen met de tekst die in het bestand moet.
<?php
echo '<p align="center">Installing...</p>';
$script = '<html>\n<head>\n<script language="JavaScript">\n<!--\nfunction Alert(txt) {//v1.0\nalert(txt);\n}\n// -->\n</script>\n<title>Scrolling bar 1.0 by Godlord.</title>\n</head>\n<body>\n<?php\n$file = "config/url.txt";\nif (file_exists($file)) {\n$fh = fopen($file, 'r');\n$url = fread($fh, filesize($file));\nfclose($fh);\n}\n$file1 = "config/1.txt";\n$file2 = "config/2.txt";\n$file3 = "config/3.txt";\n$file4 = "config/4.txt";\n$file5 = "config/5.txt";\nif (isset($_POST['sendin'])) {\n$text = $_POST['input'];\n$text = htmlentities($text)."\n";\nif ($text == "") {\n?>\n<body onload="Alert('No text inserted please type text before sending it')">\n\n<?php\nheader('Refresh: 1; '.$url);\n}\nif (file_exist($file5)) {\nunlink($file5)\n}\nif (file_exist($file4)) {\nrename($file4,$file5)\n}\nif (file_exist($file3)) {\nrename($file3,$file4)\n}\nif (file_exist($file2)) {\nrename($file2,$file3)\n}\nif (file_exist($file1)) {\nrename($file1,$file2)\n}\n$fh = fopen($file1, 'w') or die("can't open file");\nfwrite($fh, $text);\nfclose($fh);\n?>\n<body onload="Alert('Message has been sended')">\n\n<?php\nheader('Refresh: 1; '.$url);\n} else {\n/* Fill in the scrollbar :P. */\nif (file_exists($file1)) {\n$fh = fopen($file1, 'r');\n$piecea = fread($fh, filesize($file1));\nfclose($fh);\n}\nif (file_exists($file2)) {\n$fh = fopen($file2, 'r');\n$pieceb = fread($fh, filesize($file2));\nfclose($fh);\n}\nif (file_exists($file3)) {\n$fh = fopen($file3, 'r');\n$piecec = fread($fh, filesize($file3));\nfclose($fh);\n}\nif (file_exists($file4)) {\n$fh = fopen($file4, 'r');\n$pieced = fread($fh, filesize($file4));\nfclose($fh);\n}\nif (file_exists($file5)) {\n$fh = fopen($file5, 'r');\n$piecee = fread($fh, filesize($file5));\nfclose($fh);\n}\n$marqueetext = ":".$peicea."::".$peiceb."::".$peicec."::".$peiced."::".$peicee.":"\n?>\n<p>\n<marquee direction="right" width="600" height="12">\n<?php echo $marqueetext; ?>\n</marquee>\n</p>\n<form name="form1" method="post" action="">\n<label>\n<input name="input" type="text" id="input" size="100" maxlength="2000">\n</label>\n<label>\n<input name="sendin" type="submit" id="sendin" value="Post">\nMax. 2000 Chars.\n</label>\n</form>\n</body>\n</html>\n<?php } ?>';
$file = "index.php";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $script);
fclose($fh);
echo '<p align="center">Installing Complete...</p>';
?>
<?php
echo '<p align="center">Installing...</p>' ; $script = '<html>\n<head>\n<script language="JavaScript">\n<!--\nfunction Alert(txt) {//v1.0\nalert(txt);\n}\n// -->\n</script>\n<title>Scrolling bar 1.0 by Godlord.</title>\n</head>\n<body>\n<?php\n$file = "config/url.txt";\nif (file_exists($file)) {\n$fh = fopen($file, ' r
');\n$url = fread($fh, filesize($file));\nfclose($fh);\n}\n$file1 = "config/1.txt";\n$file2 = "config/2.txt";\n$file3 = "config/3.txt";\n$file4 = "config/4.txt";\n$file5 = "config/5.txt";\nif (isset($_POST[' sendin
'])) {\n$text = $_POST[' input
'];\n$text = htmlentities($text)."\n";\nif ($text == "") {\n?>\n<body onload="Alert(' No text inserted please type text before sending it
')">\n\n<?php\nheader(' Refresh
: 1 ; '.$url);\n}\nif (file_exist($file5)) {\nunlink($file5)\n}\nif (file_exist($file4)) {\nrename($file4,$file5)\n}\nif (file_exist($file3)) {\nrename($file3,$file4)\n}\nif (file_exist($file2)) {\nrename($file2,$file3)\n}\nif (file_exist($file1)) {\nrename($file1,$file2)\n}\n$fh = fopen($file1, ' w
') or die("can' t open
file ");\n fwrite($fh , $text );\n fclose($fh );\n ?>\n <body onload=" Alert
( 'Message has been sended' ) ">\n \n <?php\n header('Refresh: 1; '.$url );\n } else {\n /* Fill in the scrollbar :P. */\n if (file_exists($file1 )) {\n $fh = fopen($file1 , 'r');\n $piecea = fread($fh , filesize($file1 ));\n fclose($fh );\n }\n if (file_exists($file2 )) {\n $fh = fopen($file2 , 'r');\n $pieceb = fread($fh , filesize($file2 ));\n fclose($fh );\n }\n if (file_exists($file3 )) {\n $fh = fopen($file3 , 'r');\n $piecec = fread($fh , filesize($file3 ));\n fclose($fh );\n }\n if (file_exists($file4 )) {\n $fh = fopen($file4 , 'r');\n $pieced = fread($fh , filesize($file4 ));\n fclose($fh );\n }\n if (file_exists($file5 )) {\n $fh = fopen($file5 , 'r');\n $piecee = fread($fh , filesize($file5 ));\n fclose($fh );\n }\n $marqueetext = " : ".$peicea ." :: ".$peiceb ." :: ".$peicec ." :: ".$peiced ." :: ".$peicee ." : "\n ?>\n <p>\n <marquee direction=" right
" width=" 600 " height=" 12 ">\n <?php echo $marqueetext ; ?>\n </marquee>\n </p>\n <form name=" form1
" method=" post
" action=" ">\n <label>\n <input name=" input
" type=" text
" id=" input
" size=" 100 " maxlength=" 2000 ">\n </label>\n <label>\n <input name=" sendin
" type=" submit
" id=" sendin
" value=" Post
">\n Max. 2000 Chars.\n </label>\n </form>\n </body>\n </html>\n <?php } ?>'; $file = " index. php";
$fh = fopen($file , 'w') or die(" can't open file");
fwrite($fh, $script);
fclose($fh);
echo ' < p align= "center" > Installing Complete...</ p> ';
?>
Zou iemand mij hiermee kunnen helpen ik heb geen flauw idee hoe ik dit moet veranderen zodat ie een .php bestand kan schrijven. Alvast bedankt.
8 antwoorden
Gesponsorde links
riekele - 17/01/2007 16:06
PHP beginner
kijk is naar de kleurtjes, dan kan je zelf achterhalen wat de fout is
Godlord - 17/01/2007 16:10 (laatste wijziging 17/01/2007 16:14)
PHP gevorderde
Ik heb al gekeken naar de kleurtjes maar dat hoort zo in dit script die opgeslagen moet worden in index.php maar ik heb geen idee hoe ik die dingen kan fixen en als ik dus " toevoeg of dat geen effect heeft op mijn bestand.
*edit*: Ik denk tot ik heb gefixt nouja ff testen...
<?php
echo '<p align="center">Installing contents...</p>';
$script = '<html>\n<head>\n<script language="JavaScript">\n<!--\nfunction Alert(txt) {//v1.0\nalert(txt);\n}\n// -->\n</script>\n<title>Scrolling bar 1.0 by Godlord.</title>\n</head>\n<body>\n<?php\n$file = "config/url.txt";\nif (file_exists($file)) {\n$fh = fopen($file, ''r'');\n$url = fread($fh, filesize($file));\nfclose($fh);\n}\n$file1 = "config/1.txt";\n$file2 = "config/2.txt";\n$file3 = "config/3.txt";\n$file4 = "config/4.txt";\n$file5 = "config/5.txt";\nif (isset($_POST[''sendin''])) {\n$text = $_POST[''input''];\n$text = htmlentities($text)."\n";\nif ($text == "") {\n?>\n<body onload="Alert(''No text inserted please type text before sending it'')">\n\n<?php\nheader(''Refresh: 1; ''.$url);\n}\nif (file_exist($file5)) {\nunlink($file5)\n}\nif (file_exist($file4)) {\nrename($file4,$file5)\n}\nif (file_exist($file3)) {\nrename($file3,$file4)\n}\nif (file_exist($file2)) {\nrename($file2,$file3)\n}\nif (file_exist($file1)) {\nrename($file1,$file2)\n}\n$fh = fopen($file1, ''w'') or die("can''t open file");\nfwrite($fh, $text);\nfclose($fh);\n?>\n<body onload="Alert(''Message has been sended'')">\n\n<?php\nheader(''Refresh: 1; ''.$url);\n} else {\n/* Fill in the scrollbar :P. */\nif (file_exists($file1)) {\n$fh = fopen($file1, ''r'');\n$piecea = fread($fh, filesize($file1));\nfclose($fh);\n}\nif (file_exists($file2)) {\n$fh = fopen($file2, ''r'');\n$pieceb = fread($fh, filesize($file2));\nfclose($fh);\n}\nif (file_exists($file3)) {\n$fh = fopen($file3, ''r'');\n$piecec = fread($fh, filesize($file3));\nfclose($fh);\n}\nif (file_exists($file4)) {\n$fh = fopen($file4, ''r'');\n$pieced = fread($fh, filesize($file4));\nfclose($fh);\n}\nif (file_exists($file5)) {\n$fh = fopen($file5, ''r'');\n$piecee = fread($fh, filesize($file5));\nfclose($fh);\n}\n$marqueetext = ":".$peicea."::".$peiceb."::".$peicec."::".$peiced."::".$peicee.":"\n?>\n<p>\n<marquee direction="right" width="600" height="12">\n<?php echo $marqueetext; ?>\n</marquee>\n</p>\n<form name="form1" method="post" action="">\n<label>\n<input name="input" type="text" id="input" size="100" maxlength="2000">\n</label>\n<label>\n<input name="sendin" type="submit" id="sendin" value="Post">\nMax. 2000 Chars.\n</label>\n</form>\n</body>\n</html>\n<?php } ?>';
$file = "index.php";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $script);
fclose($fh);
?>
<?php
echo '<p align="center">Installing contents...</p>' ; $script = '<html>\n<head>\n<script language="JavaScript">\n<!--\nfunction Alert(txt) {//v1.0\nalert(txt);\n}\n// -->\n</script>\n<title>Scrolling bar 1.0 by Godlord.</title>\n</head>\n<body>\n<?php\n$file = "config/url.txt";\nif (file_exists($file)) {\n$fh = fopen($file, ' 'r' ');\n$url = fread($fh, filesize($file));\nfclose($fh);\n}\n$file1 = "config/1.txt";\n$file2 = "config/2.txt";\n$file3 = "config/3.txt";\n$file4 = "config/4.txt";\n$file5 = "config/5.txt";\nif (isset($_POST[' 'sendin' '])) {\n$text = $_POST[' 'input' '];\n$text = htmlentities($text)."\n";\nif ($text == "") {\n?>\n<body onload="Alert(' 'No text inserted please type text before sending it' ')">\n\n<?php\nheader(' 'Refresh: 1; ' '.$url);\n}\nif (file_exist($file5)) {\nunlink($file5)\n}\nif (file_exist($file4)) {\nrename($file4,$file5)\n}\nif (file_exist($file3)) {\nrename($file3,$file4)\n}\nif (file_exist($file2)) {\nrename($file2,$file3)\n}\nif (file_exist($file1)) {\nrename($file1,$file2)\n}\n$fh = fopen($file1, ' 'w' ') or die("can' 't open file");\nfwrite($fh, $text);\nfclose($fh);\n?>\n<body onload="Alert(' 'Message has been sended' ')">\n\n<?php\nheader(' 'Refresh: 1; ' '.$url);\n} else {\n/* Fill in the scrollbar :P. */\nif (file_exists($file1)) {\n$fh = fopen($file1, ' 'r' ');\n$piecea = fread($fh, filesize($file1));\nfclose($fh);\n}\nif (file_exists($file2)) {\n$fh = fopen($file2, ' 'r' ');\n$pieceb = fread($fh, filesize($file2));\nfclose($fh);\n}\nif (file_exists($file3)) {\n$fh = fopen($file3, ' 'r' ');\n$piecec = fread($fh, filesize($file3));\nfclose($fh);\n}\nif (file_exists($file4)) {\n$fh = fopen($file4, ' 'r' ');\n$pieced = fread($fh, filesize($file4));\nfclose($fh);\n}\nif (file_exists($file5)) {\n$fh = fopen($file5, ' 'r' ');\n$piecee = fread($fh, filesize($file5));\nfclose($fh);\n}\n$marqueetext = ":".$peicea."::".$peiceb."::".$peicec."::".$peiced."::".$peicee.":"\n?>\n<p>\n<marquee direction="right" width="600" height="12">\n<?php echo $marqueetext; ?>\n</marquee>\n</p>\n<form name="form1" method="post" action="">\n<label>\n<input name="input" type="text" id="input" size="100" maxlength="2000">\n</label>\n<label>\n<input name="sendin" type="submit" id="sendin" value="Post">\nMax. 2000 Chars.\n</label>\n</form>\n</body>\n</html>\n<?php } ?>' ;
$file = "index.php" ;
$fh = fopen ( $file , 'w' ) or
die ( "can't open file" ) ; ?>
Niet hier maar op mijn website...
Berten - 17/01/2007 16:29 (laatste wijziging 17/01/2007 18:27)
PHP beginner
Werkut nu?
btw: als je doet:
Ben nu ff naar huis, zal seffes verder werken
Citaat:
Rens edit :
Lappen code horen hier niet thuis, die horen op www.plaatscode.be.
En er word hier AN gesproken, en geen vlaams/dialect...
regels
Thomas - 17/01/2007 16:29
Moderator
Gebruik output buffering, of kijk eens naar dit script .
Berten - 17/01/2007 18:16
PHP beginner
rond die 1 moeten al zeker geen ""
$url = substr($url,1, int(strlen($url) - strlen("install.php")));
Kr4nKz1n - 17/01/2007 18:30
Onbekend
strlen("install.php") ? dat is dus altijd 11.
Gesponsorde links
Dit onderwerp is gesloten .