PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Safe_mode error FAILED (Upload folder could not be created.)

  1. Hi,

    Wordpress 3.4.4
    Gravity Forms 1.6.8.1

    If I run the site with safe_mode enabled (which is unfortunately required for production, yes I know all about safe_mode!) then I am unable to use image fields because doing so the form sends a blank image and the logs report:
    PHP Warning: copy(FAILED (Upload folder could not be created.)) function.copy: failed to open stream: No such file or directory in wp-content/plugins/gravityforms/forms_model.php on line 2002

    I've tried setting all the directories within wp-content to 777 and still get the same error. It appears that the problem is that when the script creates the directory it has the wrong owner and hence is unable to write to it.
    Is it possible to not create a new folder on each upload in a similar way to how wordpress is able to not "Organize my uploads into month- and year-based folders"?
    Thanks

    Posted 11 years ago on Friday December 14, 2012 | Permalink
  2. You can use the gform_upload_path filter to change where your Gravity Forms uploads will be stored: http://www.gravityhelp.com/documentation/page/Gform_upload_path

    Posted 11 years ago on Wednesday December 19, 2012 | Permalink
  3. Thanks for the reply, I've been looking into this further but think I've misunderstood what this is doing.

    The code I added to the foot of forms_model.php is:

    add_filter("gform_upload_path", "change_upload_path", 10, 2);
    function change_upload_path($path_info, $form_id){
        $wp_upload_dir = wp_upload_dir();
        $path_info["path"] = $wp_upload_dir['path'];
        $path_info["url"] = "http://www.mysite.com/wp-content/uploads/";
        return $path_info;
    }

    But I'm getting a PHP warning stating:

    PHP Warning:  copy(): Unable to access /var/www/mysite/wp-content/uploads/rgbtest1.jpg in /var/www/mysite/wp-content/plugins/gravityforms/forms_model.php on line 2002
    PHP Warning:  copy(/var/www/mysite/wp-content/uploads/rgbtest1.jpg): failed to open stream: No such file or directory in /var/www/mysite/wp-content/plugins/gravityforms/forms_model.php on line 2002

    If I'm reading this rightly it's now trying to copy from the uploads directory to somewhere else rather than write to the uploads directory...

    Any thoughts appreciated.

    Posted 11 years ago on Monday December 24, 2012 | Permalink
  4. David Peralty

    Please don't change core files. The hooks and filters code we link to belongs in your theme's functions.php file. Check out the following documentation:
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 11 years ago on Monday December 24, 2012 | Permalink
  5. Thanks for that tip. I've moved the code into my theme functions.php and updated to a vanilla copy of Gravity Forms 1.6.11 but I'm still getting the same error (line no is the only difference).

    PHP Warning:  copy(): Unable to access /var/www/mysite/wp-content/uploads/rgbtest12.jpg in /var/www/mysite/wp-content/plugins/gravityforms/forms_model.php on line 2012
    PHP Warning:  copy(/var/www/mysite/wp-content/uploads/rgbtest12.jpg): failed to open stream: No such file or directory in /var/www/mysite/wp-content/plugins/gravityforms/forms_model.php on line 2012

    I've done a bit more debugging in the actual code and at the point of the copy() command on line 2012 the file does not appear to exist (i.e. adding file_exists($path) to line 2011 outputs false).
    Similarly if I try a file upload no file is output, although I see no PHP error message.
    This is on a standard LAMP server and only occurs when safe_mode is enabled (which I require for production use) and appears to be reproducible.
    Please advise.

    Posted 11 years ago on Friday December 28, 2012 | Permalink
  6. David Peralty

    Hi again, I was talking to one of our developers and you are right, Safe Mode does create issues for our file uploads. Gravity Forms needs access to write to the uploads folder and there isn't really anything we can do about it. Also, Safe Mode has been deprecated and even removed from PHP 5.4 so it is probably not a good idea to depend on it anymore.

    http://php.net/manual/en/features.safe-mode.php

    Posted 11 years ago on Friday December 28, 2012 | Permalink