Jump to content

Can you find the cause???


mattal999

Recommended Posts

i have this code:

 

<?php
session_start();
$file = $_POST['file'];

$text = $_POST['content'];
$username = $_SESSION['userName'];
chdir($username);
$handle = fopen("$file", "x+");

chmod("$file", 0777);

fwrite($handle, $text);

chmod("$file", 0755);

echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=" . $file . "'>Here</a>";
?>

 

which returns this (posted filename = lol.php):

 

<br />

<b>Warning</b>:  fopen() [<a href='function.fopen'>function.fopen</a>]: SAFE MODE Restriction in effect.  The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>7</b><br />

<br />

<b>Warning</b>:  fopen(lol.php) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>7</b><br />

<br />

<b>Warning</b>:  chmod() [<a href='function.chmod'>function.chmod</a>]: Unable to access lol.php in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>8</b><br />

<br />

<b>Warning</b>:  chmod() [<a href='function.chmod'>function.chmod</a>]: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>8</b><br />

<br />

<b>Warning</b>:  fwrite(): supplied argument is not a valid stream resource in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>9</b><br />

<br />

<b>Warning</b>:  chmod() [<a href='function.chmod'>function.chmod</a>]: Unable to access lol.php in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>10</b><br />

<br />

<b>Warning</b>:  chmod() [<a href='function.chmod'>function.chmod</a>]: No such file or directory in <b>/home/users/uks51756/html/games4uonline.com/sites/new2.php</b> on line <b>10</b><br />

File lol.php created! Edit it Here

 

help plz!

Link to comment
Share on other sites

Something's telling me it's your php.ini settings.

 

You do have safe mode on meaning some accessibility is limited.

 

Also, your quoting is wrong for this line:

 

echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=" . $file . "'>Here</a>";

 

It should be:

 

echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>";

 

Since you already have echoed out in double quotes, variables don't need to be added on, ie.

 

echo "Hello, my name is ".$var." and I am saying hello.";
echo "Hello, my name is $var and I am saying hello.";
echo "Hello, my name is '$var' and I am saying hello."

 

All three will echo the variable correctly.

Link to comment
Share on other sites

Yeah i got one,

 

CAUSE:

$handle = fopen("$file", "x+");

 

Warning:  fopen() [<a href='function.fopen'>function.fopen[/url]]: SAFE MODE Restriction in effect.  The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 7

 

FIX:

turn off SAFE MODE

 

Link to comment
Share on other sites

well basically im making a web hosting system...

 

its flat file based...

 

when a user signs up, it makes a new folder called (their username) and registers them in the username and pwd system.

 

and i want them to create a new file in their folder but i cannot do this by using a file in sites/ when their folder is sites/(username)/.

 

help please...

 

i have tried many things.

Link to comment
Share on other sites

Like this!

 

assuming that the folder sites/test/ exists

 

<?php
$username = "test";
$filename = "sites/$username/";
$somecontent = "Blar\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "Success, wrote ($somecontent) to file ($filename)";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
?> 

Link to comment
Share on other sites

hmmm... new code:

 

<?php
session_start();
$username = $_SESSION['userName'];
$file = $_POST['file];
$filename = "$username/$file";
$somecontent = "This is a new file";
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'x+')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
?> 

 

new error:

 

Parse error: syntax error, unexpected T_STRING, expecting ']' in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 8

 

EDIT: fixed error, missing a '.

 

now i get:

 

The file mattal999/new9.php is not writable
Link to comment
Share on other sites

nobody?

 

EDIT: new code:

 

<?php
session_start();
$username = $_SESSION['userName'];
$file = $_POST['file'];
$filename = "$username/$file";
$somecontent = "This is a new file";
chmod($username, 0777);
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
?> 

Link to comment
Share on other sites

try this

 

<?php
session_start();
$username = $_SESSION['userName'];
$file = $_POST['file'];
$curpath = dirname(__FILE__);
$filename = "$curpath/$username/$file";
$somecontent = "This is a new file";
echo (chmod($curpath."/".$username, 0777))?"":"chmod failed";
if (is_writable($filename)) {
    if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "<font face='verdana' size='2'><center>File $file created! Edit it <a href='writenew.php?file=$file'>Here</a>";
    fclose($handle);
} else {
    echo "The file $filename is not writable";
}
?> 

 

or use can use

chdir($username);

Link to comment
Share on other sites

this works for me

<?php
$user = "Test";
$file = "MyFile.txt";
$CurDir = dirname(__FILE__);
$somecontent = "TEST";
$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 (!$handle = fopen($filepath, 'w+'))
	{
		 echo "Cannot open file ($filepath)";
		 exit;
	}

	// Write $somecontent to our opened file.
	if (fwrite($handle, $somecontent) === FALSE)
	{
		echo "Cannot write to file ($filepath)";
		exit;
	}

	echo "Success, wrote ($somecontent) to file ($filepath)";

	fclose($handle);

} else {
	echo "The file $filepath is not writable";
}
}
?>

Link to comment
Share on other sites

nope... code:

 

<?php
session_start();
$user = $_SESSION['userName'];
$file = $_POST['file'];
$CurDir = dirname(__FILE__);
$somecontent = "TEST";
$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 (!$handle = fopen($filepath, 'x+'))
	{
		 echo "Cannot open file ($filepath)";
		 exit;
	}

	// Write $somecontent to our opened file.
	if (fwrite($handle, $somecontent) === FALSE)
	{
		echo "Cannot write to file ($filepath)";
		exit;
	}

	echo "Success, wrote ($somecontent) to file ($filepath)";

	fclose($handle);

} else {
	echo "The file $filepath is not writable";
}
}
?>

 

returns error:

 

Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/mattal999 owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16

 

Warning: fopen(/home/users/uks51756/html/games4uonline.com/sites/mattal999/test2.phphp) [function.fopen]: failed to open stream: No such file or directory in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16

Cannot open file (/home/users/uks51756/html/games4uonline.com/sites/mattal999/test2.phphp)

 

its really not possible...

Link to comment
Share on other sites

i took out the user folder lolol after registering and then ran script:

 

Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid/gid is 1051756/1051756 is not allowed to access /home/users/uks51756/html/games4uonline.com/sites/lolol owned by uid/gid 33/33 in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16

 

Warning: fopen(/home/users/uks51756/html/games4uonline.com/sites/lolol/test9997.php) [function.fopen]: failed to open stream: No such file or directory in /home/users/uks51756/html/games4uonline.com/sites/new2.php on line 16

Cannot open file (/home/users/uks51756/html/games4uonline.com/sites/lolol/test9997.php)

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.