anubhavmax Posted September 20, 2009 Share Posted September 20, 2009 I have written a small php code that opens a file for editing in browser and edits and saves the file after editing. Here goes the code <?php // set file to read $filename = "news.txt"; $newdata = $_POST['newd']; if ($newdata != '') { // open file $fw = fopen($filename, 'w') or die('Could not open file!'); // write to file // added stripslashes to $newdata $fb = fwrite($fw,stripslashes($newdata)) or die('Could not write to file'); // close file fclose($fw); } // open file $fh = fopen($filename, "r") or die("Could not open file!"); // read file contents $data = fread($fh, filesize($filename)) or die("Could not read file!"); // close file fclose($fh); // print file contents echo "<h1>Welcome to IEEE @ NITR News Update</h1> <h4>By Anubhav Mishra</h4> <h3>Contents of File</h3> <form action='$_SERVER[php_self]' method= 'post' > <textarea name='newd' cols='100%' rows='30'>$data</textarea><br> <input type='submit' value='Change and Update'> </form>"; ?> The problem is that the code works fine on my work pc both on apache and IIS 5.1 in XP. But when i upload the file in the webserver running Windows server 2003 (IIS 6.0), it gives the following error. Notice: Undefined index: newd in E:\IEEE\update.php on line 6 Warning: fopen(news.txt) [function.fopen]: failed to open stream: No such file or directory in E:\IEEE\update.php on line 21 Could not open file! E:\IEEE\ is da parent directory where all the files are hosted. Any help would be greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/174861-php-code-working-on-my-pc-but-fails-to-work-when-uploaded-on-the-server/ Share on other sites More sharing options...
ngreenwood6 Posted September 20, 2009 Share Posted September 20, 2009 Well one problem seems to be that there is no news.txt file in the directory. Just create one and leave it blank and that should fix the second issue. The first issue may be the name. When you are posting to this page what is the name of the input? For example (<input name="thisname">) Link to comment https://forums.phpfreaks.com/topic/174861-php-code-working-on-my-pc-but-fails-to-work-when-uploaded-on-the-server/#findComment-921515 Share on other sites More sharing options...
anubhavmax Posted September 20, 2009 Author Share Posted September 20, 2009 sry..but u r wrong... all file system is intact...there is news.txt... and these are not two problems...it is the same problem itself... the code works perfect on my work pc but shows the error on the server... Probably I guess there is nothing wrong with the code but is there any thing that is to be modified in the server side... http://ieee.nitrkl.ac.in/update.php http://ieee.nitrkl.ac.in/news.txt The code given is the complete code of the file update.php.... just copy /paste the code in an empty php file and try running it....you will find it surely works.... dunno what is the problem on the server... I hav got other php scripts running there with no problem but this one shows a problem..... I even tried another script with different code changing the file..but same error....working on my pc but fails on the server... Link to comment https://forums.phpfreaks.com/topic/174861-php-code-working-on-my-pc-but-fails-to-work-when-uploaded-on-the-server/#findComment-921595 Share on other sites More sharing options...
anubhavmax Posted September 20, 2009 Author Share Posted September 20, 2009 please help sum1 Link to comment https://forums.phpfreaks.com/topic/174861-php-code-working-on-my-pc-but-fails-to-work-when-uploaded-on-the-server/#findComment-921754 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.