Jump to content

unlink() error


akimm

Recommended Posts

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
[code]
<?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>
[/code]

[code]

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']);
}
?>
[/code]

I appreciate any assistance, thanks in advance. 
Link to comment
Share on other sites

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:

[code]
<?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);
}
?>
[/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.