I am trying to serve an image to html via php script. But I am stuck and its not working :-(
Below is my image.php script
<?
$_GET['f'] = 'all_three.jpg';
$image = null;
$image = file_get_contents($_GET['f']);
header("Content-Type: image/jpeg");
echo $image;
?>
and below is my index.html
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Page Title</title>
</head>
<body>
<img src="image.php" alt="Image" />
</body>
</html>
The link to image is "hard-coded" inside the php, all I am doing is calling "image.php" to serve that hardcoded image and it does not work! What am i doing wrong?
when I view->source after loading image.php, i can see the php script
Either:
You are depending on short tags, but your server is configured to not support them.
Their use is not recommended, stop using them. Use <?php instead of <?
Or:
Your server does not support PHP. Install PHP on it.
The error is on Content-Encoding, what's Text editor are you use ? Notepad 6.x ?
If yes please try:
Encoding > Encode in UTF-8 without BOM
BOM make php file have a more content and image doesn't accept another content else image
Related
html tag is not displaying the image and I am trying to display html file through php file.
HTML file:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<img name="Userphoto" alt="Userphoto" src="img/50X50.png">
</div>
</body>
</html>
PHP file:
<form name="Dashboard">
<div class="frame1">
<?php include 'frame1.html'; ?>
</div>
</form>
HTML file is called into PHP file so path is consider of PHP one
Better way is to convert your html file into php and define your img path as
<img name="Userphoto" alt="Userphoto" src="<?php echo base_url(); ?>img/50x50.png">
Maybe your path to the image is not good since you included it in another file.
Let's say from your HTML file the path is "img/50X50.png", but if your php file is not in the same folder as your HTML code, the path isn't good.
Use absolute path and no more problems.
Have fun.
It is very likely that the image path is incorrect:
src="img/50X50.png
You can open Chrome Console to see the error message, which would indicate this, or provide another clue as to why the image hasn’t displayed.
This is my php:
<html>
<head>
</head>
<body>
<?php
include ('source\visuose\navigation.php');`enter code here`
include('source\visuose\social.php')
?>
</body>
</html>
Navigation:
<html xmlns="http://www.w3.org/1999/xhtml", lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../../css/style.css" />
Social:
<body>
<div id="facebook">
<a href="http://www.facebook.com" target="_blank">
<img src="../../images/facebook-logo.jpg" width="81" height="36" />
</a>
</div><!--facebook ends-->
</body>
</html>
Why, when running php I can't see pictures?
There is only a blank box, but I can press on them and go to my a href?
Can't be sure without seeing your file structure, but this is what it looks like;
Your "main" php is in the server root /main.php and includes source\visuose\social.php. Since social.php is included, the browser thinks it's a part of /main.php.
social.php gives the browser a relative path ../../images/facebook-logo.jpg, but since the browser thinks it's /main.php including it, it will navigate relative from that file, not source\visuose\social.php. When the browser navigates your relative path, it points to nothing useful.
You should also inspect the source of the generated page, right now you have multiple html and body tags wrapping each other in a strange way.
it has to be issue with the path of the image. In firefox You just need to right click the images and select show image. To see where it is pointing ( aka coming from ) and check for what is the intended URL for the image ?
And then repair your images path accordingly.
This is not a PHP issue
fix the src of your image
<img src="../../images/facebook-logo.jpg" width="81" height="36" />
and it would work
I am having problems with producing a Rectangle with GD - PHP. I am running XAMPP and programming on Netbeans IDE. I am new to PHP but some what fimilar with Perl.
<?php
header ("Content-type: image/png");
$newImg = ImageCreate(250,250);
$red = ImageColorAllocate($newImg,255,0,0);
ImageFill($newImg,0,0,$red);
ImagePNG($newImg);
ImageDestroy($newImg);
?>
Here is the out put.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
‰PNG
IHDRúú²"È~PLTEˆÁÿ·¿~`IDAThíÁ‚ ÿ¯nH#¿ :F¨z’IEND®B`‚ </body>
</html>
You need to stuff the html into a seperate file, and use a <img> tag to load your php script, e.g.
<html>
<body>
<img src="yourimagescript.php" />
</body>
</html>
alternative, you COULD use data uris to embed the image directly into the html, but that brings about another set of problems, e.g.
<img src="data:image/jpeg;base64,<?php echo base64_encode(imagepng($newImg, '-')) ?>/>
If you want to use binary as source for image you need to use it as follows:
<img src="data:image/png;base64,data..."/>
or if you want use it as it is in your example you need to point image src attribute to your php script from example
<img src="path/to/script.php"/>
and path/to/script.php"/ displays only data and correct header
‰PNG
IHDRúú²"È~PLTEˆÁÿ·¿~IDAThíÁ‚ ÿ¯nH#¿ :F¨z’IEND®B‚
I have an .html file with a login form and wish to recreate it and save it as a .php file. However, I'm encountering difficulties with setting the background image and other CSS related stuff.
Below is my code for the .php which I'm sure it won't provide guidance to answering my question, but I don't know where to start. I've checked W3schools and many other sites.
A great start to helping me out would on how I would include a .CSS file in .PHP file. Perhaps giving me the a quick source code example. Also, the code to set a fixed background
image would be amazing.
<?php
$url = 'C:\Users\George\Documents\HTML\bg.jpg';
?>
<html lang="en">
<head>
<title>This is a test</title>
<style type="text/css">
body
{
background-image:url('<?php echo $url ?>');
}
</style>
</head>
<body>
<p>This is a test.</p>
</body>
</html>
I found my answer.
<?php
$profpic = "bg.jpg";
?>
<html>
<head>
<style type="text/css">
body {
background-image: url('<?php echo $profpic;?>');
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hey</title>
</head>
<body>
</body>
</html>
It's not a good coding to put PHP code into CSS
body
{
background-image:url('bg.png');
}
that's it
Your question doesn't have anything to do with PHP... just CSS.
Your CSS is correct, but your browser won't typically be able to open what you have put in for a URL. At a minimum, you'll need a file: path. It would be best to reference the file by its relative path.
You should consider have other php files included if you're going to derive a website from it. Instead of doing all the css/etc in that file, you can do
<head>
<?php include_once('C:\Users\George\Documents\HTML\style.css'); ?>
<title>Title</title>
</hea>
Then you can have a separate CSS file that is just being pulled into your php file. It provides some "neater" coding.
I'm experiencing very strange problem regarding encoding PHP files in UTF-8. For example, I have two files: index.php and require.php. In index.php files I have this code
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
</head>
<?php
require 'require.php';
?>
<body>
<a></a>
</body>
</html>
In require.php I only have empty PHP tags
<?php
?>
When I open index.php and use Chrome's Element Inspector to see the output HTML I get this:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
"
"
<a></a>
</body>
</html>
Note the two strange quote marks at the begining of body. If I remove the require statement from PHP code or simply remove a tags they dissapear. What's even stranger is that if I echo something out in require.php file it gets outputed between those two quotes.
The problem goes away if I change encoding from UTF-8 to ANSI in require.php
I've been searching for answer for hours and did not found single person who has same problem.
Try add header('Content-type: text/html; charset=utf-8'); in index.php, and remove the ending '?>' from require.php.
Made worse after adding the header. Although, converting the file to UFT-8 Without BOM is worked for me! Thank you.
If you are sending a plaintext file, you will need this...
<?php
header('Content-type: text/plain; charset=utf-8');
print('中文。');
?>
For sending HTML, you'll need to change the header's "text/plain" to "text/html".