Jump to content

Display images error HELP!!!!!!


Hallic7

Recommended Posts

Hi everyone!!!!

I´m having serious problems displaying images in the browser!

The code I have is the following:

<?php

$filen = "\Servidor\WEB\ProyectoGaleria\Magic the gathering\Incinerate.jpg";
$filedir = fopen ($filen, "rb");
$contentfile = fread ($filedir, filesize($filen));
fclose ($filedir);             
echo $contentfile;             
?>

When I run this code the result is the page full of strange characters, not the image I want to see!!!
I did not have problems with .txt files, but with any type of image files happends the same!!!
Help please I´m going crazy!!!! What can I do!!??
Link to comment
https://forums.phpfreaks.com/topic/27195-display-images-error-help/
Share on other sites

You need header:
[code]
<?php
Header("Content-type: image/jpeg");
$filen = "\Servidor\WEB\ProyectoGaleria\Magic the gathering\Incinerate.jpg";
$filedir = fopen ($filen, "rb");
$contentfile = fread ($filedir, filesize($filen));
fclose ($filedir);
echo $contentfile;
?>
[/code]

Thanks very much!!!!! but now I have another error!!!! hehe

I´ll post the code again, it has some minor changes, but the error goes on!

<head>
<meta http-equiv="Content-Type" charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php

header("Content-type: image/jpeg");
$filen = "\Servidor\WEB\ProyectoGaleria\Pruebas1\8.jpg";
$filedir = fopen ($filen, "rb");
$contentfile = fread ($filedir, filesize($filen));
fclose ($filedir);             
echo $contentfile;             
?>

</body>
</html>

This is what I get now:

Warning: Cannot modify header information - headers already sent by (output started at F:\Servidor\WEB\ProyectoGaleria\prueba_abrir.php:7)

And below this, all the strange characters I was getting before!!

Help please!! I really need it!
I already tried positioning the header in different places and beetwen tags. I end up having the same error:

Warning: Cannot modify header information - headers already sent by (output started at F:\Servidor\WEB\ProyectoGaleria\prueba_abrir.php:6) in F:\Servidor\WEB\ProyectoGaleria\prueba_abrir.php on line 7

Here´s the code, I´m not sure if I´m positioning well the header.  When the code is executed the browser displays the error mentioned above and a lot of strange characters (which I believe is the image in binary or something like that!!!) Help please!!!!!

<head>
<meta http-equiv="Content-Type" charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
header("Content-type:image/jpeg");
$filen = "\Servidor\WEB\ProyectoGaleria\Pruebas1\8.jpg";
$filedir = fopen($filen,"rb");
$contentfile = fread($filedir, filesize($filen));
fclose ($filedir);             
echo $contentfile; 
?>
</body>
</html>
Ok!!! I fix everything!!!!
Thanks for the help!!!

The problem was because I was mixing text with images, and the content-type didn´t allowed this!!!

I manage to display the image with echo and the code:

echo "<img src="."$galeria_imagen/$nombre_ima.jpg".">";

Where the variables are dynamic values, so easy!!! hehe

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.