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
https://forums.phpfreaks.com/topic/22049-unlink-error/
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
https://forums.phpfreaks.com/topic/22049-unlink-error/#findComment-99128
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.