Gform upload path

m (Usage)
m (Examples)
Line 30: Line 30:
== Examples ==
== Examples ==
-
This example changes the notification's BCC field, adding values from posted fields.
+
This example changes the upload path and url for the File Upload field.
<pre class="brush:php">
<pre class="brush:php">
<?php
<?php
-
add_filter("gform_upload_path", "change_upload_path", 20, 2);
+
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
function change_upload_path($path_info, $form_id){
   $path_info["path"] = "/new/path/";
   $path_info["path"] = "/new/path/";
-
   $path_info["url"] = "http://new_url.com/images/";
+
   $path_info["url"] = "http://yourdomainhere.com/new/path/";
   return $path_info;
   return $path_info;
}
}

Revision as of 16:18, 23 November 2011

Description

This filter is executed before uploading a file (by the File Upload or Post Image fields). It can be used to change the location where uploaded files are stored.

Usage

Applies to all forms

<?php
add_filter("gform_upload_path", "upload_path", 10, 2);
?>


Applies to a specific form. In this case, form Id 5

<?php
add_filter("gform_upload_path_5", "upload_path", 10, 2);
?>

Parameters

$path_info

(Array) The upload path to be filtered. It is an associative arrays with two keys that must be specified.
$path_info["path"] = "Full physical path to upload folder";
$path_info["url"] = "Full URL to upload folder";

$form

(Form Object) The current form.

Examples

This example changes the upload path and url for the File Upload field.


<?php
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
   $path_info["path"] = "/new/path/";
   $path_info["url"] = "http://yourdomainhere.com/new/path/";
   return $path_info;
}
?>

Source Code

This filter is located in forms_model.php

Search the Documentation