Support

Account

Home Forums Front-end Issues File download URL incorrect. Cannot download uploaded file.

Solved

File download URL incorrect. Cannot download uploaded file.

  • I am trying to download a PDF which has been uploaded through the File Field Type. I’ve followed all the instructions here

    http://www.advancedcustomfields.com/resources/field-types/file/

    The link is being created but the source of that link is not pointing to the source of the file.

    http://localhost:81/clientName/solutions/crop/productName/331,%20,%20productName%20Label%20AFR,%20,%20,%20application/pdf,%20http://localhost:81/clientName/files/productName-Label-AFR.pdf

    I am not quite understanding the structure of the URL.

    What is different in my WP setup is the media files are being stored outside of WordPress inside a folder called “files” and perhaps this is what is causing the problem.

    Here’s the code I am using:

    <?php
    $attachment_id = get_field(‘download_label_afrikaans’);
    $url = wp_get_attachment_url( $attachment_id );
    ?>
    <?php if( get_field(‘download_label_english’) ): ?>
    “><span></span>Label (ENG)
    <?php endif; ?>

    Thank you.

  • Deleted – one topic at a time

  • Deleted – one topic at a time

  • Hi @sixfootjames

    Your code shows that your image field is returning an ARRAY. Please review the documentation to discover how to output the correct array information.

    Thanks
    E

  • Hi @sixfootjames

    Your first issue can occur when you have updated some, but not all of the WP PATH constants. Please make sure you have correctly set constants for:

    WP_PLUGIN_DIR
    WP_CONTENT_DIR
    ABSPATH

    Thanks
    E

  • Hi @elliot

    Thanks for getting back to me. I’ve deleted the two posts that talked about images so as not to confuse matters.

    I’ve since also reverted back to the “wp-content/uploads” folder to simplify matters so I don’t need to worry about the WP PATH constants as mentioned (is my thinking correct?)

    My understanding therefore is as follows:

    • Create Group
    • Create Upload Field
    • In theme page add according to documentation:
      <?php if( get_field('download_label_english') ): ?>
      														<a class="label-en" href="<?php the_field('download_label_english'); ?>"><span></span>Label (ENG)</a>
      													<?php endif; ?>

    But I still get an array URL even though I am not going the array route.

    Many thanks

  • @elliot I have removed my comments about the images. Please delete them and yours if you feel it waters down the main topic. Thanks

  • Right, so what I have done is created a blank WP site. Added ACF, and in my theme page added <a href="<?php the_field('gallery_file'); ?>" >Download File</a> where “gallery_file” is the name of the test field.

    This has worked 100% as expected when a refreshed the page so now I am trying to figure out what I have done wrong with my other project.

    Is it possible that by setting the “wp-content/uploads” to use a different folder by using define( 'UPLOADS', ''.'files' ); I have effectively changed all the paths on a permanent basis and if that is the case, how do I undo this so that it points back to “wp-content/uploads”

  • Finally managed to find the problem!
    In the group the Return Value needs to be File URL rather than File Object which is the default setting under the File Field Type options.

    Many thanks Elliot

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘File download URL incorrect. Cannot download uploaded file.’ is closed to new replies.