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 🙂
-
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
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
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
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, 3 months ago by
jlohl.
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
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-Lucwhat is the user path now?
now I have $dropboxpath = “mmm/”;
That works well and the txt files go to dropbox folder mmmI’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, 3 months ago by
jlohl.
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
Thanks a lot Nickolas, it works perfectly !
-
This reply was modified 9 years, 3 months ago by
The topic ‘Additional Fields in text file?’ is closed to new replies.