I have tried to use absolute paths and it is giving me a permission denied error because it cannot find it on line 102.
I also think I am defining the variable that holds /home/user/xxx/events.txt too much. Do you think I could put $datafile = "/home/user/xxx/events.txt" at the top of the page and then link to it in the code?
<?
#####################
#
# Events compose
#
#####################
session_start();
require_once("includes/config.php");
if ($_SESSION["valid"] == true) {
/* If action is delete */
if($_GET["action"] == "delete") {
$file = file('/home/user/xxx/events.txt');
$data = '';
for ($i=0; $i<count($file); $i++)
{
if (!strstr($file[$i],$_GET['id']))
{
$data .= $file[$i];
}
}
$data2 = trim($data);
$fp = fopen('/home/user/xxx/events.txt',"w");
if ($fp)
{
fwrite($fp,$data2);
fclose($fp);
}
header("Location: events.php?message=deleted");
}
/* if form submitted */
if ($_POST["action"] == "Submit") {
/* image processing */
if ($_POST["imagefile"] != "") {
if (($_FILES['imagefile']['type'] == "image/jpeg")||($_FILES['imagefile']['type'] == "image/gif")) {
copy($_FILES['imagefile']['tmp_name'], "gallery/".$_FILES['imagefile']['name'])
or die("Could not copy");
} else {
echo "<br /><br />";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br/>";
}
}
/* set variables */
$title = $_POST["title"];
$timearrive = $_POST["timearrive"];
$date_start = $_POST["date_start"];
$date_finish = $_POST["date_finish"];
$about = $_POST["about"];
$status = $_POST["status"];
$imageornot = $_POST["chkbox"];
$image = $_FILES['imagefile']['name'];
$id = rand(1000, 9999);
$filename = "/home/user/xxx/events.txt";
$pipe = "|";
$cr = "\n";
/* corrolate into data clusters */
$data1 .= $title . $pipe . $timearrive . $pipe . $date_start . $pipe . $date_finish . $pipe . $about . $pipe . $id . $pipe . $status;
if ($imageornot =="y") {
$data2 .= $pipe . $imageornot . $pipe . $image;
}
$dataall = $data1 . $data2 . "\n";
/* open file */
$fp = fopen("/home/user/xxx/events.txt","a");
if ($fp) {
/* Write information to the file */
fwrite($fp,$dataall);
fclose($fp);
/* write a message that it has worked */
header("Location: events.php?message=added");
}
}
/* messages */
if ($message =="added") {
$main .='<div class="confirm">Event added. <a href="events.php">Refresh</a></div>';
}
if ($message =="deleted") {
$main .='<div class="confirm">Event deleted. <a href="events.php">Refresh</a></div>';
}
/* if the form has not been submitted */
if ($_POST["action"] != "Submit") {
/* display all events in a list */
$main .= '<div class="eventlist"><ul>';
$userinfo1 = file("/home/user/xxx/events.txt");
foreach($userinfo1 as $key1 => $val1) {
/* Put data into an array */
$data1[$key1] = explode("|", $val1);
}
for ($k = 0; $k < sizeof($userinfo1); $k++) {
$main .= '<li><b>' . $data1[$k][0] . '</b>';
$main .= ' - <a href=events_edit.php?action=edit&id=' . $data1[$k][5] . '>Edit</a> :: <a href=events.php?action=delete&id=' . $data1[$k][5] . '>Delete</a></li>';
}
}
$main .= '</ul>';
/* display form */
$main .= '<div>
<fieldset>
<legend>Add event</legend>
<form action="events.php" method="post" name="frm" enctype="multipart/form-data">
<div class="form">
<label for="title">Title: </label><input type=text name=title>
<br /><br />
<label for="timearrive">Arrival time: </label><input type=text name="timearrive">
<br /><br />
<label for="date_start">Date start: </label><input type=text name="date_start">
<br /><br />
<label for="date_finish">Date finish: </label><input type=text name="date_finish">
<br /><br />
<label for="about">About this event: </label><textarea rows=10 cols=40 name="about"></textarea>
<br /><br />
<label for="status">Past event?</label>
<select name=status>
<option>Yes</option>
<option selected="selected">No</option>
</select>
<br /><br />
<label for="checkbox">Image? </label><input type="checkbox" name="chkbox" onclick="showhidefield()" value="y">
<br /><br />
<div id="hideablearea" style="display:none;">
<br />
<input type="file" name="imagefile"><br /><br />
</div>
<input class=button type=submit value=Submit>
<input type=hidden name=action value=Submit>
</div>
</form>
</fieldset>
</div>
';
} else {
header("Location: index.php");
}
$page = "events";
require_once("includes/template.php");
?>