WordPress.org

Support

Support » How-To and Troubleshooting » PHP not displaying images from database

PHP not displaying images from database

  • Hello, I am running a php plugin (http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/) and I am trying to post an image on a page. The image is in the following location: /wp-content/images/. However, the image will not display (instead it displays a broken image link). I have looked at several posts about this problem, but nothing seems to work. Any help is appreciated! Thanks! (code below)

    <img src="<?php bloginfo('template_directory'); ?>/wp-content/images/pic.jpg" />

Viewing 15 replies - 1 through 15 (of 15 total)
  • Try this:

    <?php echo '<img src="' . content_url() . '/images/pic.jpg' . '" />'; ?>

    Just wandering why you use bloginfo(‘template_directory’)

    Anyhow use get_bloginfo(‘template_directory’) in this case.

    @michaelsambol

    providing a link to the page displaying the problem, or copying the corresponding portion of output html would help tremendously for these types of questions.

    Being able to investigate the actual html helps pinpoint the problem

    @threecows Adding “get_” in front of “bloginfo” worked! Thanks!

    Sorry, I have one follow-up. What should I do if the link to the image is dynamic, not static. Instead of /wp-content/images/pic.jpg, I need $picture

    I am trying to populate a table of images from a folder

    I rewrote this code assuming you have a folder named “/wp-content/images” in your template folder.

    $img_dir = TEMPLATEPATH . '/wp-content/images/' ;
    $files=glob($img_dir . '*.*');
    foreach ($files as $file) {
    	$fileinfo = getimagesize($file);
    	if ($fileinfo[0] > 0) { //it's an imagefile
    		$pathinfo = pathinfo($file);
      	 	echo '<img src="' . get_bloginfo('template_directory') . '/wp-content/images/' . $pathinfo['filename'] . '.' . $pathinfo['extension'] . '" />';
    	}
    }

    Nothing is printing :/

    I tried to simplify it and print just one image, but the image doesn’t print. Here is the code I used:

    echo '<img src="' . get_bloginfo('template_directory') . '/wp-content/images/pic.jpg' . '" />';

    What is the full path of the folder containing the images ??

    Check things out to construct the correct URI’s :

    echo ABSPATH . "<br />";
    echo content_url() . "<br />";
    echo TEMPLATEPATH . "<br />";
    echo get_bloginfo('template_directory');

    I installed the plugin you use for displaying php.
    Put the code in a post and it is indeed not printing anything.
    Look’s like the plugin won’t handle complicated strings.

    I suggest you’d better make a custom plugin instead of using this ‘php show plugin’ for this purpose.

    Here’s the code for the test-plugin:
    http://pastebin.com/WEiQJqfr

    Just copy the code into a new textfile and name it testplugin.php
    Upload the file to your plugin directory.
    Activate it.
    Add the shortcode [test] to a post.

    YES THANK YOU Threecows. It works. You’re amazing. Appreciate the help.

    @threecows haha now the test plugin seems to be interfering with the theme … for example, the theme’s shortcode for button ( [button] ) no longer produces a button..

    Strange…
    The only thing I can think of is the shortcode and the name “test” is not unique enough.

    Try this:
    In testplugin.php find and replace ALL words matching “test” with “myown”.
    (this will change the plugin name and function names as well which is no problem at all)

    Upload end replace testplugin.php
    Use the shortcode [myown] in the post.

    Aha 🙂
    The button will probably show up, but you won’t see it in the mess of images displayed in the post…
    You’ll have to edit the testplugin and add br tags for instance.
    You can best edit the function “my_test_replstring”

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘PHP not displaying images from database’ is closed to new replies.
Skip to toolbar