• Resolved maxwilliam

    (@maxwilliam)


    Hi,

    I have files that are stored on my Google Drive account (because they are too heavy). Then, I transform the sharing url into a direct download url.

    Ex : https://drive.google.com/file/d/FILE_ID/edit?usp=sharing
    To : https://drive.google.com/uc?export=download&id=FILE_ID

    When I launch the link in my browser i can downloads the file directly.
    I inserted this link in my product and now the user can download the file but the name of the file is not taken into account.
    For example my file is called “hello.zip”, when the user goes on his account to download the file he gets “uc” file every time.
    I tried to download this file because the weight is the same, I renamed this “uc” file into “hello.zip” and it works.

    How to fix this problem ?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter maxwilliam

    (@maxwilliam)

    I think I found something. In the file : includes/class-wc-download-handler.php
    I changed line 433 :
    header( ‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”;’ );
    In : header( ‘Content-Disposition: attachment; filename=”blablabla.doc”;’ );

    Now this changes the name of the file when i try to download. So there is a problem getting the file name from the url…

    Thread Starter maxwilliam

    (@maxwilliam)

    I found a temporary solution.
    In the file: includes/class-wc-download-handler.php
    At line 195 : $filename = current (explode (‘?’, $filename));

    That’s what’s causing the problem because with Google Drive the name of the file is not transmitted in the url. So I try to recover this file name using curl but I didn’t succeed…

    So, when you create your product and add a file to download, you must fill the name of your file and your url. So I use the name field to name my file (same name as my file stored in my Google Drive with extension).

    Then, I made changes at line 194 :

    if ( strstr( $filename, ‘?’ ) ) {
    $filename = current( explode( ‘?’, $filename ) );
    }

    In :

    if ( strstr( $filename, ‘?’ ) ) {
    $filename = current( explode( ‘?’, $filename ) );

    $product = wc_get_product( $product_id );
    $drive_filename = $product->get_downloads();
    foreach( $drive_filename as $key => $each_download ) {
    $filename = $each_download[“name”];
    }
    }

    It works for the moment 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Download Problem’ is closed to new replies.