Title: Additional Fields in text file?
Last modified: December 7, 2016

---

# Additional Fields in text file?

 *  Resolved [lonzoo](https://wordpress.org/support/users/lonzoo/)
 * (@lonzoo)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/)
 * Hi,
 * I’d like to get a hold of data in additional fields from a java application, 
   but as i don’t want to access the sql-database for the additional fields i’m 
   looking for a different solution.
    The best solution for me would be, if i could
   somehow get the data from textfields into a .txt-file right next to the uploaded
   file. Is this possible?
 * Anyway great plugin. Best regards 🙂

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8524407)
 * Hi, yes you can do this. However you need to implement one of the filters of 
   the plugin (with PHP code). I can give you instructions if you want.
 * Your application runs on the server? If yes, there are other ways also, like 
   executing an OS command with exec PHP function.
 * Let me know.
 * Regards
 * Nickolas
 *  Thread Starter [lonzoo](https://wordpress.org/support/users/lonzoo/)
 * (@lonzoo)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8552818)
 * Thanks for your quick response!
    Yes, sounds perfect, please give instructions.
   I already implemented file-renaming on wfu_before_file_check_handler in my functions.
   php, like you described in another thread.
 * The application runs on my local server, while wordpress runs on a remote webserver.
   In 5 minute-intervals i’m connecting via ftp to download any newly uploaded files,
   thus a simple file next to the uploaded file will work best, i think.
 * Best regards
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8555117)
 * Here is the hook:
 *     ```
       if (!function_exists('wfu_after_upload_handler')) {
       	function wfu_after_upload_handler($changable_data, $additional_data) {
       		foreach ( $additional_data["files"] as $file ) {
       			$fileext = wfu_fileext($file["filepath"], true);
       			$txtpath = preg_replace("/\\$fileext$/", ".txt", $file["filepath"]);
       			$contents = "";
       			foreach ( $file["user_data"] as $userdata )
       				$contents .= ( $contents == "" ? "" : "\n" ).$userdata["label"].": ".$userdata["value"];
       			file_put_contents($txtpath, $contents);
       		}
       		return $changable_data;
       	}
       	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
       }
       ```
   
 * The above hook will create a .txt file with additional user data for every file
   uploaded. The .txt file has the same filename with the uploaded file. Any previous.
   txt files with the same name will be overridden.
 * Regards
 * Nickolas
 *  [jlohl](https://wordpress.org/support/users/jlohl/)
 * (@jlohl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8886150)
 * Hello,
    above hook only adds a text file to wordpress uploads directory. Is it
   possible to send those text files to Dropbox instead when one uploads to Dropbox
   folders ? Second question : can one only send a text file while uploading one
   type of file (ie add a text file only when uploading a .jpg but not when uploading
   other files ?
 * Regards
    JL
    -  This reply was modified 9 years, 6 months ago by [jlohl](https://wordpress.org/support/users/jlohl/).
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8888326)
 * Hi, the hook below will create text files only for .jpg images and will send 
   them to dropbox in root folder. You can change the dropbox upload path if you
   want ($dropboxpath variable):
 *     ```
       if (!function_exists('wfu_after_upload_handler')) {
       	function wfu_after_upload_handler($changable_data, $additional_data) {
       		$dropboxpath = "/";
       		$deletelocal = false;
       		foreach ( $additional_data["files"] as $file ) {
       			$fileext = wfu_fileext($file["filepath"], true);
       			if ( $fileext == ".jpg" ) {
       				$txtpath = preg_replace("/\\$fileext$/", ".txt", $file["filepath"]);
       				$contents = "";
       				foreach ( $file["user_data"] as $userdata )
       					$contents .= ( $contents == "" ? "" : "\r\n" ).$userdata["label"].": ".$userdata["value"];
       				file_put_contents($txtpath, $contents);
       				$fileid = wfu_log_action('include', $txtpath, get_current_user_id(), '', '', get_current_blog_id(), '', null);
       				wfu_dropbox_add_file_to_queue($fileid, $txtpath, $dropboxpath, $deletelocal, "last");
       			}
       		}
       		return $changable_data;
       	}
       	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
       }
       ```
   
 * Regards
 * Nickolas
 *  [jlohl](https://wordpress.org/support/users/jlohl/)
 * (@jlohl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8894745)
 * Thanks a lot Nickolas,
    awesome support ! the script works perfectly, but what
   is needed in the dropbox path to add the user path (so the text file goes to 
   same folder as the jpg file) ?
 * Regards
    Jean-Luc
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8894966)
 * what is the user path now?
 *  [jlohl](https://wordpress.org/support/users/jlohl/)
 * (@jlohl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8895067)
 * now I have $dropboxpath = “mmm/”;
    That works well and the txt files go to dropbox
   folder mmm
 * I’d like to have something like $dropboxpath = “mmm/%username%/%userdata2%/”;
   
   so I tried with some variations like $dropboxpath = “mmm/” . $username . “/” .
   $userdata2 . “/”;
 * but no success !
    Regards JL
    -  This reply was modified 9 years, 6 months ago by [jlohl](https://wordpress.org/support/users/jlohl/).
 *  Plugin Author [nickboss](https://wordpress.org/support/users/nickboss/)
 * (@nickboss)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8895192)
 * Ok, try this code:
 *     ```
       if (!function_exists('wfu_after_upload_handler')) {
       	function wfu_after_upload_handler($changable_data, $additional_data) {
       		$user = wp_get_current_user();
       		if ( $user->ID == 0 ) $username = "guest";
       		else $username = $user->user_login;
       		$dropboxpath = "mmm/$username/".$additional_data["files"][0]["user_data"][1]["value"];
       		$deletelocal = false;
       		foreach ( $additional_data["files"] as $file ) {
       			$fileext = wfu_fileext($file["filepath"], true);
       			if ( $fileext == ".jpg" ) {
       				$txtpath = preg_replace("/\\$fileext$/", ".txt", $file["filepath"]);
       				$contents = "";
       				foreach ( $file["user_data"] as $userdata )
       					$contents .= ( $contents == "" ? "" : "\r\n" ).$userdata["label"].": ".$userdata["value"];
       				file_put_contents($txtpath, $contents);
       				$fileid = wfu_log_action('include', $txtpath, $user->ID, '', '', get_current_blog_id(), '', null);
       				wfu_dropbox_add_file_to_queue($fileid, $txtpath, $dropboxpath, $deletelocal, "last");
       			}
       		}
       		return $changable_data;
       	}
       	add_filter('wfu_after_upload', 'wfu_after_upload_handler', 10, 2);
       }
       ```
   
 * Nickolas
 *  [jlohl](https://wordpress.org/support/users/jlohl/)
 * (@jlohl)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8895393)
 * Thanks a lot Nickolas, it works perfectly !

Viewing 10 replies - 1 through 10 (of 10 total)

 The topic ‘Additional Fields in text file?’ is closed to new replies.

 * ![](https://ps.w.org/wp-file-upload/assets/icon-256x256.png?rev=3714699)
 * [Iptanus File Upload](https://wordpress.org/plugins/wp-file-upload/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-file-upload/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-file-upload/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-file-upload/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-file-upload/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-file-upload/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [jlohl](https://wordpress.org/support/users/jlohl/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/additional-fields-in-text-file/#post-8895393)
 * Status: resolved