Jump to content

[SOLVED] Permissions, permissions, permissions...


mattal999

Recommended Posts

hi, how would i make it so that the $file variable is not allowed to have ../ or ./ in it?

 

<?php
error_reporting(0);
session_start();
$user = $_SESSION['userName'];
$file = $_POST['file'];
$CurDir = dirname(__FILE__);
if($_POST['folder'] != '') {
$user = $user . '/' . $_POST['folder'];
} else {
$user = $user;
}
$NewDir = "$CurDir/$user";
$filepath = $NewDir."/".$file;

if (!file_exists($NewDir) && !is_dir($NewDir) ) mkdir($NewDir, 0755);

if( is_dir($NewDir) )
{
	if (is_writable($NewDir))
	{
if($_POST['folder'] != '') {
$folder = $_POST['folder'];
} else {
$folder = '';
}
if (!$handle = fopen($filepath, 'x+'))
		{
			 echo "<center><font face='verdana' size='2'>The file $file already exists, edit it <a href='writenew.php?file=" . $folder . "" . $file . "' style='border-bottom: dotted #000000 1px; text-decoration: none;'><font color='000000'>here</a>";
			 exit;
		}

		echo "<center><font face='verdana' size='2'>Success, made a new file $file, edit it <a href='writenew.php?file=" . $folder . "" . $file . "' style='border-bottom: dotted #000000 1px; text-decoration: none;'><font color='000000'>here</a>";

		fclose($handle);

	} else {
		echo "<center><font face='verdana' size='2'>The file $file could not be made";
	}
}
?>

 

thanks

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.