Jump to content


Photo

unlink() error


  • Please log in to reply
2 replies to this topic

#1 akimm

akimm
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 26 September 2006 - 12:04 AM

This file is meant to glob() my entrys directory, and pull all txt extension files into a foreach loop, which will then be printed with a yes or no below them.  The yes means I approve the file and want it to be written to the server in guestbook.txt which can then be used  as my guestbook entry file, after its written I want it unlinked anyway because it will be written to a new fie.  If i click no, I want the file to be unlinked immediately.
approve.php
<?php
foreach (glob("entrys/*.txt") as $files) {
	?>
<table>
<form method="POST" action="ad.php">
<tr><td><?php include($files);?></td></tr>
	<tr><td><h2>yes</h2></td><br>
<td><input type="radio" name="name" value="yes" id="yes"><label for="yes">Yes</label></td></tr>
<tr><td><h2>no</h2></td><br>
<td><input type="radio" name="name" value="no" id="no"><label for="no">No</label><</td></tr>
	<?php
	echo "</table>";
	}
?>
<input type="submit" value="submit for addition to guestbook" name="guestbook">
</form>


ad.php
<?php
$fp = fopen('guestbook.txt', 'w');
if($_POST['name'] == "yes" && $fp) {
fwrite($fp, $files);
fclose($fp);
unlink($_POST['name']);
	}
if($_POST['name'] == "no") {
unlink($_POST['name']);
}
?>

I appreciate any assistance, thanks in advance. 

#2 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 26 September 2006 - 06:23 PM

it might work better if you put the file information in the form hidden.

<input type='hidden' name='files' value='<? echo $files; ?>'>

Then on ad.php change to this:

<?php
$files = $_POST['files'];
$fp = fopen('guestbook.txt', 'w');
if($_POST['name'] == "yes" && $fp) {
fwrite($fp, $files);
fclose($fp);
unlink($files);
	}
if($_POST['name'] == "no") {
unlink($files);
}
?>


#3 akimm

akimm
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 September 2006 - 12:44 AM

Thank you Jocka, I will give that a try.  I appreciate your help  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users