WordPress.org

Ready to get started?Download WordPress

Forums

If.. then.. else with images (1 post)

  1. Steve Bruner
    Member
    Posted 6 years ago #

    I'm not a programmer, but I really thought this would work. Want to write the following if.. then.. else.. statement:

    -The file is the name of the post and is in the uploads directory
    IF
    file exists
    THEN
    tell me it exists
    ELSE
    tell me it doesn't

    For some reason the code below outputs "the blog url" and then says "the file doesn't exist"... when it does.

    Any help would be greatly appreciated!!

    Thanks
    Steve

    <?php

    $url = '/wp-content/uploads/' . get_the_ID();
    $image_file = get_the_title();
    $full_url = bloginfo('url') . $url . '/' . $image_file;

    if (file_exists($full_url)) {
    echo "The file exists";
    } else {
    echo "The file does not exist";
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic