Ok so the below creates a new folder IF I cmod the folder I want to create it in to 777. Nothing else works, but Im worried 777 is not secure. I dont really understand cmod that well but as far as I know 777 means that the whole world can write to my folder, and I dont want that. Am I doing something wrong? Shouldnt this work at cmod 775 or something like that? What IS the correct cmod for folders when you want to use php to create more folders inside them anyway?
//make sure all is lowercase
$username_l = strtolower($username);
$folder = strtolower($username{0});
// set up ftp connection
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!";
exit; }
//create folder
if (!file_exists("users/$folder/$username_l")) {
mkdir("users/$folder/$username_l");
chmod("users/$folder/$username_l", 0777); }
// close the FTP stream
ftp_close($conn_id);