Hallic7 Posted November 14, 2006 Share Posted November 14, 2006 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 More sharing options...
sinisake Posted November 14, 2006 Share Posted November 14, 2006 You need header:[code]<?phpHeader("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] Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124357 Share on other sites More sharing options...
Hallic7 Posted November 14, 2006 Author Share Posted November 14, 2006 Thanks very much!!!!! but now I have another error!!!! heheI´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! Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124360 Share on other sites More sharing options...
sinisake Posted November 14, 2006 Share Posted November 14, 2006 You must put header info on thee top of the script ABOVE any other output. Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124361 Share on other sites More sharing options...
Hallic7 Posted November 14, 2006 Author Share Posted November 14, 2006 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 7Here´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><?phpheader("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> Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124483 Share on other sites More sharing options...
blear Posted November 14, 2006 Share Posted November 14, 2006 The header() command is not above the other code. HTML is code. Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124496 Share on other sites More sharing options...
Hallic7 Posted November 14, 2006 Author Share Posted November 14, 2006 Thanks Everybody!!!I noticed that the error is in the code order!!! I´m still having problems, but they are now different! thanks! Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124560 Share on other sites More sharing options...
Hallic7 Posted November 14, 2006 Author Share Posted November 14, 2006 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 Link to comment https://forums.phpfreaks.com/topic/27195-display-images-error-help/#findComment-124658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.