renno Posted November 21, 2006 Share Posted November 21, 2006 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 streamfwrite($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 3I'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 https://forums.phpfreaks.com/topic/27983-file-permissions-please-help/ Share on other sites More sharing options...
craygo Posted November 21, 2006 Share Posted November 21, 2006 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 https://forums.phpfreaks.com/topic/27983-file-permissions-please-help/#findComment-128059 Share on other sites More sharing options...
renno Posted November 23, 2006 Author Share Posted November 23, 2006 Thanks very much, will let you know how it goes... Link to comment https://forums.phpfreaks.com/topic/27983-file-permissions-please-help/#findComment-128897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.