Elusid Posted September 7, 2006 Share Posted September 7, 2006 So here is my code[code]<?php $review = $_POST['review'];$dir = 'reviews/'; for ($i=0;$i<1000;$i+=1) { if (!file_exists($dir . i+'')) { $file = fopen($dir . i+'', "a"); fwrite($file, $review);break;}}fclose($file);echo "<meta http-equiv='refresh' content='2;url=http://flamelicker.com/commentsuccess.html'>"; ?>[/code]and it's writing to the root directory and not reviews/ what's wrong with it? Link to comment https://forums.phpfreaks.com/topic/19966-problem-with-writing-file-to-the-right-location/ Share on other sites More sharing options...
ToonMariner Posted September 7, 2006 Share Posted September 7, 2006 Try to define teh path explicitly i.e. $dir = $_SERVER['DOCUMENT_ROOT'] .'/reviews';That is assuming the reviews dir is in teh root dir. Link to comment https://forums.phpfreaks.com/topic/19966-problem-with-writing-file-to-the-right-location/#findComment-87507 Share on other sites More sharing options...
Elusid Posted September 7, 2006 Author Share Posted September 7, 2006 Ok so I am trying that right now. I assume you wanted 'DOCUMENT_ROOT' to be replaced with a URL so this is what I have now. [code]<?php $review = $_POST['review'];$dir = $_SERVER['http://flamelicker.com/media/wips/tds/'] .'/reviews'; for ($i=0;$i<1000;$i+=1) { if (!file_exists($dir . i+'')) { $file = fopen($dir . i+'', "a"); fwrite($file, $review);break;}}fclose($file);echo "<meta http-equiv='refresh' content='2;url=http://flamelicker.com/commentsuccess.html'>"; ?>[/code]EDIT and no it still writes to the root and now reviews/ Link to comment https://forums.phpfreaks.com/topic/19966-problem-with-writing-file-to-the-right-location/#findComment-87511 Share on other sites More sharing options...
live_ex3me Posted September 7, 2006 Share Posted September 7, 2006 no :) .. u should use exactly $dir = $_SERVER['DOCUMENT_ROOT'] .'/reviews'; $_SERVER['DOCUMENT_ROOT'] will return the path that ur php file has it ( if u use i.e. : "c:/program files/apache group/apache/htdocs", for example). .'/reviews'; --> stands for the folder u want to place the uploaded file. this folder's path will be: "c:/program files/apache group/apache/htdocs/reviews" Link to comment https://forums.phpfreaks.com/topic/19966-problem-with-writing-file-to-the-right-location/#findComment-87575 Share on other sites More sharing options...
Elusid Posted September 8, 2006 Author Share Posted September 8, 2006 Ok so I solved the problem on my own. It ends up that the "i" needed a $ because it's a variable woops... so here is the code that writes the file to the right place.[code]<?php $dir = 'reviews/';$review = $_POST['review'];for ($i=0;$i<1000;$i+=1) { if (!file_exists($dir . $i+'')) { $file = fopen($dir . $i . '.txt', "a+"); fwrite($file, $review); break;}}fclose($file);echo "<meta http-equiv='refresh' content='2;url=http://flamelicker.com/commentsuccess.html'>"; ?>[/code]but now I have another problem. It's suposed to make the first text file writen in the folder 1 then 2 then 3 and so on. Only problem right now is that it makes file 0.txt which is right butn then I go to make a file again with this code and it's SUPOSED to make a file 1.txt but it just adds to 0.txt... what's wrong with this code? Link to comment https://forums.phpfreaks.com/topic/19966-problem-with-writing-file-to-the-right-location/#findComment-88111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.