Jump to content

Problem with writing file to the right location


Elusid

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.