• Resolved Mad Max

    (@mad_max)


    Hello, I’m a developer and I’m writing some code to dynamically add a Download Monitor file to an Elementor form email message, as attachment, using the file id.

    Following documentation on plugin website, I was able to retrieve the url of a download by its id, with this code:

    $file_id=1218;
    $file = download_monitor()->service( 'download_repository' )->retrieve_single( $file_id );
    $fileurl = $file->post->guid;

    How can I retrieve the file’s full local path?

    • This topic was modified 1 year, 8 months ago by Mad Max.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Razvan Aldea

    (@raldea89)

    Hello @mad_max ,

    You can use our File Manager class to retrieve the path of the file: https://github.com/WPChill/download-monitor/blob/master/src/FileManager.php#L47 depending on your found $fileurl.

    Hope this helps!

    Warmly,
    Razvan

    Thread Starter Mad Max

    (@mad_max)

    Hello @raldea89 and thanks for the super quick reply!
    I’ve tried the method parse_file_path( $file_path ) of class DLM_File_Manager, but it always return an array with 2 empty elements, if called with my file url that is like this

    https://mysite.ext/download/2378/?tmstv=1678986055

    where obviously “download” is the configured endpoint for downloads and the links correctly starts the download of the file when pasted in a browser address bar.

    Any advice?

    Regards

    Plugin Author Razvan Aldea

    (@raldea89)

    Yes, I misunderstood what you have retrieved, sorry.

    You have the Download Object, so you can retrieve the file paths like here. This will return an array of paths, from which you can choose one. After that you can use the File Manager Class I’ve mentioned before.

    You can inspire from our trigger function in order to achieve what you want.

    Warmly,
    Razvan

    Thread Starter Mad Max

    (@mad_max)

    Thank you very much for pointing me in the right direction!

    Plugin Author Razvan Aldea

    (@raldea89)

    Gladly ?? !

    Have a wonderful day!
    Razvan

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Programmatically get file path from id’ is closed to new replies.