Jump to content

File Permissions... Please Help!


renno

Recommended Posts

I have used php to create a directory on my remote webserver using:

[code]mkdir("../$com_name1");[/code]

However when I now try to create / add / write files (still using php) to this directory I get permission errors.
This code works fine when I'm testing it on my own computer (localhost), but is failing when I try to execute it after uploading to the web...

Can someone see where I'm going wrong?

[code]$maxlines=500; //change this to set the maximum lines

$lines=file("../temp.php"); //Get an array with the lines
$numlines= (count($lines)>=50) ? ($maxlines-1) : (count($lines)-1); //number of lines to write

$fp = fopen ("../{$_POST['company']}/index.php", 'w+');
// Convert from array to string
$string="";
for($i=0; $i <= $numlines; $i++)
$string .= $lines[$i];

//write to file and close stream
fwrite($fp, $string);
fclose($fp);[/code]

I also tried to change permissons using [code]chmod ("/Test2", 777);[/code] but I recieved the error message:

Warning: chmod() [function.chmod]: open_basedir restriction in effect. File(/Test2) is not within the allowed path(s): (/home/folder:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/folder/public_html/chmod.php on line 3

I'm getting a little frustrated now because I can't even delete the folders I've created without contacting my hosting company!

Many thanks...
Link to comment
Share on other sites

the user that apache uses on your web server cannot go into folders below public_html if your file chmod.php is located in the public_html folder then when you create a folder do not use ../foldername. That will go back one folder and you will get permission errors. Best thing to do is use the absolute path for your folder creation instead of reletive paths. Also chmod the folder as soon as you make it. Also, some hosting companies will not allot chmod of 777 so the highest you can go is 775.

[code]mkdir("/home/folder/public_html/Test2", 0775);[/code]

Ray
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.