To migrate where Gravity Forms stores uploads, first you need to add a filter to your functions.php
I needed to do this as a wanted a secure place and the default location was giving me problems.
Create a directory of your server that is visible from the web, and secure it with .htaccess appropriately e.g. http://weavervsworld.com/docs/other/passprotect.html
This is code for functions.php
<?php add_filter("gform_upload_path", "change_upload_path", 10, 2); function change_upload_path($path_info, $form_id){ $path_info["path"] = "/home/mydomain/public_html/safe/"; $path_info["url"] = "http://mydomain.com/safe/"; return $path_info; } ?>
The filter is explained here -> http://www.gravityhelp.com/documentation/page/Gform_upload_path
And then move the files from old place to new, FTP will do fine.
Then you need to update the database to change the location of the old files. You can use PhpMyAdmin if you have it.
UPDATE wp_rg_lead_detail SET value = REPLACE( value, 'http://mydomain/wp-content/gravityoldpath/', 'http://mydomain/safe/' ) WHERE value LIKE ( '%http://mydomain/wp-content/gravityoldpath/%' )
Note the table name may have a non wp_ prefix and on a multi site it will have a blog id , eg. xx_999_rg …
Note by default Gravity stores uploads in month folders, so you may have to iterate through several months, and you may have to deal with the odd duplicate file if you are combining into one folder.
Obviously, not just apply the code above without thinking about the path names etc as it won’t simply work copying and pasting.
You could extend the filter to user date(‘y’) and date (‘m’) to replicate the folder structures, but I’m not sure if Gravity will create new folders or you would have to code a bit like this, as I haven’t tested it.
<?php if (!file_exists('path/to/directory')) { mkdir('path/to/directory', 0777, true); } ?>
by
Tags:
Leave a Reply