rlweb
13-05-2007, 05:52 PM
<?php
$path = '../../pages/';
// Get file
if (!isset($_GET['file'])) { die('Invalid File'); }
$file = $_GET['file'];
// Create file path
$filepath = $path . $file;
// Get file extension
$ext = explode('.', $file);
$extension = $ext[count($ext)-1];
// Is this file editable or not?
// Check if extension matches an invalid one
$invalid = array('exe', 'doc', 'jpg', 'gif', '');
if (in_array(strtolower($file['extension']), $invalid)) {
die('Can\'t edit this file. Not suitable for editing. Please go back.');
}
// Form submitted?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check if new data has been set
if (!isset($_POST['newfile'])) {
die('Please enter some new data for this file.');
}
// Write new data
$f = fopen($filepath, 'w');
fwrite($f, $_POST['newfile']);
fclose($f);
// Redirect
header ('Location: index.php');
} else {
// Get file data
$f = fopen($filepath, 'r');
$data = fread($f, filesize($filepath));
fclose($f);
// Show edit form
$title = 'Filemanager - Edit File:' . htmlentities($file);
include ('header.php');
?>
<h2>Edit File: <?php echo htmlentities($file); ?></h2>
<form method="POST">
<textarea name="newfile" rows="20" cols="80"><?php echo $data; ?></textarea>
<br />
<input type="submit" name="submit" value="Save File" />
</form>
<?php
include ('footer.php');
}
?>Thanks before hand. The Problem is that the code adds / on every " every time i open the file how can i stop this?
$path = '../../pages/';
// Get file
if (!isset($_GET['file'])) { die('Invalid File'); }
$file = $_GET['file'];
// Create file path
$filepath = $path . $file;
// Get file extension
$ext = explode('.', $file);
$extension = $ext[count($ext)-1];
// Is this file editable or not?
// Check if extension matches an invalid one
$invalid = array('exe', 'doc', 'jpg', 'gif', '');
if (in_array(strtolower($file['extension']), $invalid)) {
die('Can\'t edit this file. Not suitable for editing. Please go back.');
}
// Form submitted?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Check if new data has been set
if (!isset($_POST['newfile'])) {
die('Please enter some new data for this file.');
}
// Write new data
$f = fopen($filepath, 'w');
fwrite($f, $_POST['newfile']);
fclose($f);
// Redirect
header ('Location: index.php');
} else {
// Get file data
$f = fopen($filepath, 'r');
$data = fread($f, filesize($filepath));
fclose($f);
// Show edit form
$title = 'Filemanager - Edit File:' . htmlentities($file);
include ('header.php');
?>
<h2>Edit File: <?php echo htmlentities($file); ?></h2>
<form method="POST">
<textarea name="newfile" rows="20" cols="80"><?php echo $data; ?></textarea>
<br />
<input type="submit" name="submit" value="Save File" />
</form>
<?php
include ('footer.php');
}
?>Thanks before hand. The Problem is that the code adds / on every " every time i open the file how can i stop this?