views:

30

answers:

3

Hey Folks,

Didn't got any luck finding an answer on google , so this is my last try before trying other methods.

I have a script like this:

        // get current year and month
        $cur_year = date('Y');
        $cur_month = date('m');
        $long_type = $this->getFile_longtype();

        $folder = $_SERVER['DOCUMENT_ROOT']."/".FOLDER_CMS."/uploads/$long_type/$cur_year/$cur_month";

        // check whether the folder exists
        if(!is_dir($folder)){

            // try to make the folder recursively
            if(!mkdir($folder,"0777",true)){

                logError($message, __FILE__, __LINE__);
                throw new Exception("Failure creating proper directories");

            }

        }

to make it work , I chmod'ed the uploads directory and all it's files and dirs to 777 ( beter suggestion here? )

The long type evaluates to 'images' and this is a directory has already been created on the server.

Now , the script create the folder named with year with the permissions 341. This not wat I want because it terminates the recursive folder buildup or blocks it's content from me.

Any help or suggestions?

php version : 5.2.5

configure command : './configure' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-soap' '--enable-sockets' '--enable-wddx' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mhash=/opt/mhash/' '--with-mssql=/usr/local/freetds' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-pspell' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-ttf' '--with-xmlrpc' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr'

A: 

The real permissions depend on the parameter to mkdir and the umask. The umask is subtracted from the permissions given to mkdir. Try setting your umask to 0 before doing the mkdir.

Sjoerd
this did not changes anything except that the permissions changed from 341 tot 441 or something like that.
Sam Vloeberghs
+2  A: 

Don't use the string "0777", use 0777.

Alex Howansky
Alex , you rock!
Sam Vloeberghs
+1  A: 

As mentioned by Alex, you suppose to enter OCTAL value not a STRING also, for security reasons never give full permission to folders use 0755 instead.

Nazariy
thx for the security suggestion!
Sam Vloeberghs
Correction: never != newer
Geekster
what permission should I give the files that I will store in those folders?
Sam Vloeberghs
Thank you Geekster, just finished my coffee..
Nazariy
For files use 644
Nazariy
ok thx for this useful lesson!
Sam Vloeberghs