0

I am using XAMPP for APACHE server on localhost:8080 (I had to change the default port for it to work). Assume that I have the rest of the html needed to run. Here is the current code:

home.html

<body>
<script src="main/profile.php"></script>
</body>

profile.php

<?php
$imagepath ="omj/logo.jpg";
$image = imagecreatefromjpeg( $imagepath);
header('Content-Type: image/jpeg');
imagejpeg($image);
?>

I tried referencing the following articles to no avail:

http://www.configure-all.com/howto_display_image.php

How to display images from a folder using php - PHP

Edit I got the image to work using HTML by simply moving the image folder inside the html folder. Now the question remains, why isn't the php code running to show the image?

The image path is within the directory of the html file. Like this: /htmlfolder/imagefolder/image.jpg while html file is /htmlfolder/file.html

7
  • Apparently it is a priority for some to cast down votes instead of giving the answer. I'm still not sure how to set this up. Akitha_MJ's answer did not work thus far. Commented Jun 4, 2017 at 14:37
  • Why is the src of your script a php file? You seem to have a misunderstanding of how php works. Commented Jun 4, 2017 at 14:53
  • I'm running a PHP script that shows the image. Commented Jun 4, 2017 at 14:57
  • You can't run a php script like that. Php is a server side language but the script tag is for client side code. Generally you would put JavaScript in a script tag. Commented Jun 4, 2017 at 14:59
  • So how do I do it? Every website has a different way to do the same thing. One website used the script tag. Now I'm bewildered enough to post it on this website, hoping that someone actually knows how to do it properly. Commented Jun 4, 2017 at 15:02

4 Answers 4

0

An html file cannot run php code.

Change your file name from home.html to home.php.

Then change this line:

<script src="main/profile.php"></script>

to

<?php echo '<img src="omj/logo.jpg"/>'; ?>
Sign up to request clarification or add additional context in comments.

7 Comments

The thing is that I have to leave it as HTML, the rest of the code is using HTML and I just want to run the picture through PHP.
Why do you have to leave it as html?
In short, the webpage is structured as html. I don't know if it is possible to do all of the structuring in PHP, although I would like to do it that way.
Php can use html. You can leave the page as it is but just change the file extension to .php
Am I better off just leaving it in HTML for now? I suppose I could do it just to move on and learn more before doing something complicated like that, but there isn't a lot of documentation on PHP. The official PHP documentation looks just as confusing as Java API.
|
0

So simple, " PHP optimally used single quotes '. Use standard html within string!

echo ' <img src="php.gif" /> ';

Comments

0

Try this

<?php $input = '<img src="/image/your.jpg" title="you are title " alt="any"/>'; $sx = simplexml_load_string($input); var_dump($sx); ?>

3 Comments

it doesn't load in html document and opening the php document shows a bunch of text: object(SimpleXMLElement)#1 (1) { ["@attributes"]=> array(3) { ["src"]=> string(13) "/omj/logo.jpg" ["title"]=> string(14) "you are title " ["alt"]=> string(3) "any" } }
I used the whole line above.
Are you sure to use single quotes in $input? I would think that it would not parse the string to do what we want.
0

As I said use with a variable like below

<?php 
$image_url='images/your.png';
?>

<img src="<?php echo $image_url;?>">

6 Comments

Close! I have a broken image sign. I'm double checking the spelling.
Okay then check the link to image
Nothing yet, is there something I have to do with permissions of the folders or configuration settings with APACHE/XAMPP?
Are you using Linux distro
XAMPP/APACHE through Windows 10 Home. It runs the rest of the code properly (i.e. background image, text, CSS, etc.).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.