• Resolved dkoukoul

    (@dkoukoul)


    Hello,
    after upgrading to UM 2.1.12 a functionality that I had working by directly uploading files to users through FTP and then inserting the data in the wordpress database is not working anymore. I upload a file to wp-content/uploads/ultimatemember/userid/somefile.pdf and then INSERT the filename to exam_report_pdf and the corresponding metadata to exam_report_pdf_metadata as meta_key in the usermeta table of the wordpress database.

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter dkoukoul

    (@dkoukoul)

    Can someone help me with this? I want to find a way to upload files to users directly by FTP and then inserting the relevant information to the DB
    Thanks

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dkoukoul

    What was the last version of UM before updating it to the latest version? Did you run the migration after updating it to the latest version?

    Regards,

    Thread Starter dkoukoul

    (@dkoukoul)

    Last version was 2.0.43. I noticed also that when I updated the UM plug in I updated WordPress and PHP version into 7.3, I am not sure if this has any relevance though. Regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dkoukoul

    Do you still have copies of your site with version 2.0.43? I suggest that you create a testing site where you must update the UM via Plugin manager and then run the UM Migration that will be displayed above the Dashboard. One you’ve migrated, you can now move your site to another server with the latest version of WP and PHP.

    Regards,

    Thread Starter dkoukoul

    (@dkoukoul)

    Hi @champsupertramp thanks for the reply. I have done that. The plug in works ok. I just need help in restoring the extra functionality that I had working where I was able to upload files via FTP directly to a user’s folder ../wp-content/uploads/ultimate-member/userid/filename.pdf and then make them appear on their um profile by inserting the metadata to the database at the usermeta table using the meta_key “exam_report_pdf” and “exam_report_pdf_metadata”. Is there a um function available in the api to do this as my previous method does not seem to work anymore as I see that the plugin is working by renaming the files and then retrieving the download link using the nonce functionality… Thanks for your time.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dkoukoul

    You can try this but ensure that you’ve made a full backup of your site before you run this code snippet: https://gist.github.com/champsupertramp/5bc9e1211fc6d1451dc379610768b111

    Usage:

    add_action('init', function(){
      // Users to have import files, empty array means all users
     $arr_users = [
           1
      ];
    um_import_files( "image01.jpg", "test_image_upload", 'image', $arr_users );
    um_import_files( "image02.png", "test_file_upload", 'file', $arr_users );
    });

    In your case, you need this for all users:
    um_import_files( "filename.pdf ", "exam_report_pdf", 'file');

    Or just specific users:

    $arr_user_ids = [
           1,
           8,
          12
      ];
    um_import_files( "filename.pdf ", "exam_report_pdf", 'file',  $arr_user_ids );

    Files should be in the /wp-content/uploads/ultimatemember/<user_id>
    and File fields are already added to UM Profile Form via UM Form Builder.

    Let me know if this works for you.

    Regards,

    • This reply was modified 3 years, 4 months ago by Champ Camba.
    Thread Starter dkoukoul

    (@dkoukoul)

    Thanks for the detailed answer @champsupertramp I’ll try it and get back to you!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hey @dkoukoul

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards,

    Thread Starter dkoukoul

    (@dkoukoul)

    Hello @champsupertramp I had the time to test this unfortunately it is not working as intended.
    The file is renamed and the entries in the database are there but the file is not shown on the um profile of the user. I did some file uploads manually from the um form to check for differences in the database entries and I noticed the following:
    When I do a manual file upload the meta_key of exam_report_pdf takes a value of a file name which has a longer filename than the file that exists in the actual folder and also is defined as “original_name” in the metadata.
    for example:
    In a manual upload that works I see:
    exam_report_pdf = file_685b8555_b041e7a4a06a730fe61929e01b3063fd6655d4ef.pdf
    and this as basename “file_b041e7a4a06a730fe61929e01b3063fd6655d4ef.pdf” and the filename that exists in the uploads folder.
    While in our case the filename in the folder is the same as the basename and the entry in the exam_report_pdf.
    I do not know if this “_685b8555” which seems to be added comes from UM or from a wordpress function. But I guess this is what we are missing to make it work. You have been of great help already and thanks for your time!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dkoukoul

    I’ve updated the code snippet in the link.
    https://gist.github.com/champsupertramp/5bc9e1211fc6d1451dc379610768b111

    This code line was changed from update_user_meta( $user_id, $meta_key, $movefile['file_info']['basename'] );

    to

    update_user_meta( $user_id, $meta_key, wp_basename( $file_path ) );

    It should fix the basename now.

    Regards,

    • This reply was modified 3 years, 4 months ago by Champ Camba.
    Thread Starter dkoukoul

    (@dkoukoul)

    Hello @champsupertramp thank again for your time and help. Unfortunately this does not seem to resolve the issue as the wp_basename returns the filename as it is stored in the server without the extra characters that seem to be the case when I upload the file manually. I was looking into the UM code for file uploading but unfortunately haven’t detected yet how this filename gets generated. I will keep on trying and if I find something else I’ll keep this post updated.

    Thread Starter dkoukoul

    (@dkoukoul)

    Hi again, I just noticed that I may have described what I have noticed wrongly.
    In a user where I download the file manually
    I see the file uploaded on the uploads/ultimate-member/<user-id>/ as
    file_93be7a94_00592ecbfcfffe0339b60344240a3b9223af4361.pdf (notice the characters between the two “_”)
    In the usermeta table for this user I see the following entries
    meta_key exam_report_pdf with meta_value file_93be7a94_00592ecbfcfffe0339b60344240a3b9223af4361.pdf (the file as it exists on the folder)
    and meta_key exam_report_pdf_metadata with meta_value
    a:7:{s:4:”name”;s:109:”<domain>/wp-content/uploads/ultimatemember/temp/file_00592ecbfcfffe0339b60344240a3b9223af4361.pdf”;s:13:”original_name”;s:47:”<filename>.pdf”;s:8:”basename”;s:49:”file_00592ecbfcfffe0339b60344240a3b9223af4361.pdf”;s:3:”ext”;s:3:”pdf”;s:4:”type”;s:15:”application/pdf”;s:4:”size”;i:2130374;s:11:”size_format”;s:4:”2 MB”;}

    Notice how the basename is different (the characters between the two “_” are not there) while the name has ultimatemember/temp/.
    Any hints to why?
    Thanks again for your time and help

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @dkoukoul

    I’m able to download the file after the manual upload with the code. It shows the correct file name when viewing the file via Profile Form. Are you able to download and view the files via Profile Form? It also doesn’t show the /temp/ directory after running the manual upload with the code.
    https://drive.google.com/file/d/1hkoa2EMsmxNWc_bZE1iJiiU2Xba1vd3l/view?usp=sharing

    Regards,

    Thread Starter dkoukoul

    (@dkoukoul)

    I am not able to view the file with the UM profile form. The file is not shown in the profile. Thanks for your time I will look further into it.

    Thread Starter dkoukoul

    (@dkoukoul)

    Hello again @champsupertramp I am still trying to debug this. I have double-triple checked the db and the code, everything looks ok, I dived into the UM code to check if there was a check somewhere that would make the file not show and I am wondering if I am missing a um function call after the uploading. Currently your code is in a php file that is being loaded as a template in a page file where the parameters are passed (filename, userid etc). Should I be calling any hooks or additional functions after um_import_files?
    Thanks again for your time

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Direct file upload not working’ is closed to new replies.