mercredi 7 mars 2018

PHP can't create and write to file

I have a small website which creates HTML pages with given content.

But there is a problem in PHP. I checked the code and I didn't see any problems.

PHP(Webserver) Output: PHP 7.0.27-1 Development Server started at Wed Mar 7 12:21:57 2018 Listening on http://192.168.1.105:80 Document root is /root/Desktop/code/web/1 Press Ctrl-C to quit. [Wed Mar 7 12:26:23 2018] 192.168.1.106:60258 [200]: / [Wed Mar 7 12:26:32 2018] PHP Warning: fopen(/pages/page-2018-03-07.html): failed to open stream: No such file or directory in /root/Desktop/code/web/1/echo.php on line 3 [Wed Mar 7 12:26:32 2018] PHP Warning: fwrite() expects parameter 1 to be resource, boolean given in /root/Desktop/code/web/1/echo.php on line 5 [Wed Mar 7 12:26:32 2018] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /root/Desktop/code/web/1/echo.php on line 6 [Wed Mar 7 12:26:32 2018] 192.168.1.106:60261 [200]: /echo.php

My PHP code: <?php $newfilepath = "/pages/page-" . date("Y-m-d") . ".html"; $newfile = fopen($newfilepath, "w"); $content = $_POST['content']; fwrite($newfile, $content); fclose($newfile); echo "<html><head><title>Finished!</title></head><body>URL to new page: " . $newfilepath . "</body></html>"; ?>




Aucun commentaire:

Enregistrer un commentaire