2

I have using the same code in create a new page. During the preview time, the image show perfectly, but image broken after published. I have attached the code and print screen for preview and publish mode. Is it problem occur because of the image included is php file? Please refer to the wordpress link due to here unable to attached link more than 2.Thanks for help.

My question post at Wordpress: https://wordpress.org/support/topic/image-appear-in-preview-but-broken-in-publish-wordpress?replies=3#post-6466511

<html>
<h3>This is where I want to display my graph</h3>
<img src="Example1.php" />
</html>

I need to upload a php file to generate an graph (image). Add media unable to insert php files. I tried to include the phpfile, it shown some error.

whywhy
  • 97
  • 7

1 Answers1

0

Exactly: you cannot display the output of a PHP file via an img tag. In fact, you cannot run any PHP within a post or page on WordPress. There are plugins you can add to run PHP scripts within a post or page, such as Insert PHP. This one allows the inclusion of PHP code through the use of shortcodes.

Hope this helps! :)

kittykittybangbang
  • 2,380
  • 4
  • 16
  • 27
  • i had installed Exec PHP plugin which similar to the Insert PHP plugin. It actually can display the graph in preview mode (http://i184.photobucket.com/albums/x184/Akasha_92/Preview_zps698b7a15.png), but after publish it show broken image like this (http://i184.photobucket.com/albums/x184/Akasha_92/Broken_zps75c196fa.png) – whywhy Jan 22 '15 at 02:34
  • Perhaps WordPress' PHP or your theme's PHP is interfering with it, which is why it renders in preview mode, but breaks when run with the rest of the site. In that case, it could be one of a plethora of causes; I would try renaming variables first-- maybe you're declaring a variable that's already in use in another bit of code. – kittykittybangbang Jan 22 '15 at 14:31
  • He is not includign php in the page. He is displaying a php file as an image. This is very much possible, see here: http://stackoverflow.com/questions/900207/return-a-php-page-as-an-image – Niels Abildgaard Jan 23 '15 at 07:56
  • @NielsAbildgaard Thanks for your input. However, by using a PHP file to echo an image, you _are_ including PHP in the page--you're using a PHP script to echo an image. In WordPress, this is not possible without a plugin. – kittykittybangbang Jan 23 '15 at 14:06