Jump to content

Archived

This topic is now archived and is closed to further replies.

BlackKite

Simple Create A File Problem

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I may be wrong, but could you not add the new files in something another than public_html?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...[code]<?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);
?> [/code]

But apparently this is wrong because I get the following error...[code]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[/code]

Share this post


Link to post
Share on other sites
The errors means that DNS lookup is failing.
Can you not connect to your site via FTP and change the permissions?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

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.