Jump to content


Photo

Simple Create A File Problem


  • Please log in to reply
11 replies to this topic

#1 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 14 July 2006 - 06:30 AM

Hm... wow do I feel like a noob now. Aah well, here it goes.

Im designing a open source control panel in php that allows you to create files and them have them listed on your site automatically without the hassle of going through cpanel (or whatever panel). It gives admin permission to add users so that they can have others add files also. But I'm having a problem that keeps appearing. Depending on if phpsuexec is installed or not directories have to be set to 777 or 755. I pretty sure its really unsafe to set files and folders to 777 , especially your public_html folder. Yet, in order to create a file in public_html I need to set it to 777 or i get a permissions error. Is there any way around this?

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 14 July 2006 - 07:38 AM

Can you not CHMOD the directory to 0777, create the file, then drop it back down to 0755? Pain in the arse I know, but I've found that's the only way around issues like this. I've had to do this when peoples servers have been configured in an odd way where PHP runs under a user with odd access-rights...

The amount of time that your files will be set to 0777 would be pretty minimal, a second or so at the absolute most I think.

#3 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 08:30 AM

I may be wrong, but could you not add the new files in something another than public_html?

#4 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 14 July 2006 - 10:48 AM

But public_html is the public facing folder isn't it?
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#5 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 July 2006 - 10:56 AM

public_html is the folder you can access from the internet. But im pretty sure you can write things to folders higher up than puclic_html with a php script because you can use relative links.

#6 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 14 July 2006 - 07:12 PM

Is there a way to set it tp 777 and then drop it back to 755 using php?

And yes I could have it so it creates files in a higher folder, but what if someone wants to put something in their main public_html folder.

#7 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 14 July 2006 - 07:36 PM

chmod()

#8 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 14 July 2006 - 08:07 PM

Aah, would make sense. Ok, I'll give it a try. Thanks ;)

#9 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 15 July 2006 - 04:55 AM

Ick... thats not working. Seems like I dont have the permission to set permissions via chmod()? I understand though, that theres a way to do it via an ftp connection? I've tried this but I can't quite get it to work. Im putting the following code in...
<?php
$file = 'public_html/';

$ftp_user_name = "XXXXXXX";
$ftp_user_pass = "XXXXXXXX";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// try to chmod $file to 777
if (ftp_chmod($conn_id, 0777, $file) !== false) {
 echo "$file chmoded successfully to 777\n";
} else {
 echo "could not chmod $file\n";
}

// close the connection
ftp_close($conn_id);
?>

But apparently this is wrong because I get the following error...
Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/jaboo12/public_html/staff2/guide_p/game_p.php on line 22

Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/jaboo12/public_html/staff2/guide_p/game_p.php on line 25

Fatal error: Call to undefined function: ftp_chmod() in /home/jaboo12/public_html/staff2/guide_p/game_p.php on line 28


#10 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 15 July 2006 - 05:53 PM

Anyone?

#11 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 15 July 2006 - 06:24 PM

The errors means that DNS lookup is failing.
Can you not connect to your site via FTP and change the permissions?
<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#12 BlackKite

BlackKite
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 15 July 2006 - 07:10 PM

Well I can... but that defeats the purpose. I want the script to change it to 777 and then change it back to 750 once complete becuase having yuor public_html at 777 always isn't safe.

Why is it failing, is there an error in the script... something im missing or didnt set right?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users