The blog

Project Pier upload error: Failed to create folder

I’m evaluating a collaboration/project management web application called Project Pier. So far I like it, but I got a weird upload error when I was testing file uploads. The error read:

1
Failed to create folder: /var/...xxxx.xxx/httpdocs/uploads/

My first reaction was of course to check permissions on the /upload directory. It was already set to 777, so I was a bit confused.

A little research led me to this page on Project Pier’s forums. It of course mentioned a solution posted on another page on the same forums. This solution involved replacing the default function force_mkdir() with a new one.

I modified the file

1
 /var/...xxxxx.xxx/httpdocs/environment/functions/files.php

and replaced the original force_mkdir() with the code found directly on the second forum page. It worked! Some people reported it didn’t work for them, but it worked for me under Linux, RedHat, Apache 2.x, PHP 5.1.x.

Here’s martinlang’s replacement code, reposted for your convenience. This is identical to the code he posted at this page.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function force_mkdir($path, $chmod = null) {
  if(is_dir($path)) return true;
  $forced_path = '';
  $real_path = str_replace($_SERVER["DOCUMENT_ROOT"], '', $path);
  $forced_path = $path != $real_path ? $_SERVER["DOCUMENT_ROOT"] : '';

  $real_path = str_replace('\', '/', $real_path);
  $parts = explode('
/', $real_path);

  foreach($parts as $part) {
    if($forced_path == '
') {
      $start = substr(__FILE__, 0, 1) == '
/' ? '/' : '';
      $forced_path = $start . $part;
    } else {
      $forced_path .= '
/' . $part;
    } // if

    if(!is_dir($forced_path) && $forced_path!='
/') {
      if(!is_null($chmod)) {
        if(!mkdir($forced_path)) return false;
      } else {
        if(!mkdir($forced_path, $chmod)) return false;
      } // if
    } // if
  } // foreach

  return true;
} // force_mkdir

Hope this helps someone out!

3 Responses to “Project Pier upload error: Failed to create folder”


  1. sufehmi
    2008.11.16

    Hi Steve, thanks for sharing this ! Searching for said error message on Google listed this article on the top result.

    I’ve applied the fix, and my Project Pier install is now alright.

    Thanks again !


  2. Douglas
    2008.12.15

    Thanks Steve this helped me a lot. Thanks for putting everything on one page.

    I did have a problem copying and pasting the code from this page as the quotation marks in the code on this page seem to be the smart quotes and caused a whitescreen when pasted directly into the file.

    Cheers.


  3. pato
    2010.08.13

    didnt worked for me… i copied the exact same code

Leave a Reply