I've seen that many people have problems with "Safe Mode On" settings in CMS Made Simple (CMSMS), when trying to upload one or more files to a newly created directory. The problem isn't trivial so the solution (that I came up with) is more a "work around" than a fix.

My case is as follows: "I have a client that has changed to a new hosting parter where it's not possible to disable the Safe Mode setting". Thus, when the user wants to upload new files they first create a new directory and then upload the file int this directory.

The problem is that the newly created directory has new permissions, typically with httpd rights rather than user right. Thus, it's only possible to create the directory but not to upload any files to the directory. The solution is to use ftp_mkdir in php instead. That way we can log in to the account and create the directory with user rights. Pretty simple if you think about it. In CMSMS you need to go to admin directory and open the file "imagefiles.php" and go to approx. line no. 123 (from v.1.2.3). Customize the following code such that it fits you own ftp account:

//mkdir($dir."/".$_POST['newdir'], 0777);
$server='ftp-server-address';

// ftp server $connection = ftp_connect($server);
// connection // login to ftp server $user = "ftp-username";
$pass = "ftp-pass";
$result = ftp_login($connection, $user, $pass);
$newDir = $dir.$_POST['newdir'];
$newDir = substr($newDir, 30);

//only for my server solution - might be diff. for you // check if connection was made
if ((!$connection) || (!$result)) { } else {
   if(ftp_mkdir($connection,$newDir)) {
      // create directory ftp_chmod($connection, 0777, $newDir);
} else { }
ftp_close($conn_id);
// close connection //exit();
}
audit(-1, $_POST['newdir'], 'Created Directory ddd');

NOTE: this solution worked with my hosting partner, surftown.dk. Let me know if you have another fix that might work. I hate this safe-mode problem......

Anonymous's picture

Nice! Additional info: php5

By Birger Eriksson (not verified) | 2008.02.25- 10:41

Nice!
Additional info: php5 is required to get "ftp_chmod" to work.

Anonymous's picture

Nice workaround! Have you

By Ed (not verified) | 2008.02.28- 17:18

Nice workaround!

Have you delved any further into using this approach for other issues, such as module installation or theme installation? I've searched briefly through the site files, but my understanding of php isn't strong enough to reverse engineer these issues.

Any thoughts?

Anonymous's picture

Hey guys. Thx for your

By Henrik Hedegaard (not verified) | 2008.02.28- 18:06

Hey guys.

Thx for your replies.

@Ed: no, I haven't delved further down to merging this approach with module / theme installs.

But it should be possible to use this approach as a general upload functionality in CMSMS.

If I get the time to develop such a module I'll post it both on this website and on cmsmadesimple.org

Anonymous's picture

Cool, I'll poke around in the

By Ed (not verified) | 2008.03.12- 04:51

Cool, I'll poke around in the code a bit as well, if I get a chance.

And glad I checked back; I just downloaded fontdoc, which you posted about after this post!

Anonymous's picture

People should read this.

By Dea (not verified) | 2008.10.29- 04:30

People should read this.

Anonymous's picture

[...] Solution Use the ftp

By p2e.dk/noter » SAFE MODE / mkdir() solution (not verified) | 2008.12.24- 00:26

[...] Solution Use the ftp functions in PHP to create the folders Se how at Henrik Hedegaard [...]

Anonymous's picture

Works like a charm - you are

By Kasper (not verified) | 2008.12.24- 00:32

Works like a charm - you are the man !

Made a solution for the Typo3 install tool:
http://p2e.dk/noter/?p=217

Note for PHP4:
Use "ftp_site($connection,"CHMOD 0777 " . $newDir);" to set the permissions

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].

More information about formatting options

Twitter - my latest burps

Around the web in 30 links