Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18080

Re: Show picture in window

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Show picture in window
Date 2019-10-19 10:00 +0200
Message-ID <h0vu4nFf97cU1@mid.individual.net> (permalink)
References <qoe4nd$jla$1@news2.open-news-network.org>

Show all headers | View raw


On 19/10/2019 06.50, Heiko Wetteborn wrote:

> ist de.comp.lang.php tot?

Never subscribed to de.* as German ain't among the languages I use in my 
day to day life, so no clue.


> Kann mir mal jemand auf die Sprünge helfen, wie ich das Problem 
> korrigieren kann?
> Wenn ich statt
>     Header ("Content-type: image/jpeg");
>     readfile($picname);

Most likely some white space in the end of your file that causes the 
image to break, if you see warnings about not being able to set headers 
as data already sent, then you most likely have UTF BOM.

> ein
> echo $picname
> einsetze, erhalte ich den kompletten Pfad zum Bild angezeigt, der 
> definitiv stimmt.

 > foreach (glob($dir) as $filename)
 > {
 >    $eintraege[] = $filename;
 > }
 > $picname = $eintraege[$bildnr - 1];

This one do not guarantee that you will get the right image, the files 
listed in the array may be sorted by text or even be in the order the 
image was found on disk, so you would need to extract the number from 
the filename and use it as the index number.

Try with this one:
<?php
include("function.php");
$bildnr=$_GET['bildnr'];
if(is_integer($bildnr)) {
   $filepath = documentroot() . "/fotoalbum/" . $bildnr . ".jpg";
   if(file_exists($filepath)) {
     header("Content-type: image/jpeg");
     header('Content-Length: ' . filesize($filepath));
     readfile($filepath);
     exit;
    }
}
echo "Bild nicht gefunden<br>";
?>
The big difference here is that we don't get garbage in the end of the 
file included in the image, which could cause your problem, as we have 
the exit after readfile(). Also this one will be faster, specially if 
you have a lot of files in the directory.
\r\n will not generate a new line when viewed in the browser, you need 
to use a html-tag as <br> or <br /> depending on which standard you try 
to use.


-- 

  //Aho

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Show picture in window Heiko Wetteborn <heiko2912@gmail.com> - 2019-10-19 06:50 +0200
  Re: Show picture in window "J.O. Aho" <user@example.net> - 2019-10-19 10:00 +0200
  Re: Show picture in window Jan Hansen <jhjjhjhhansen@gmail.com> - 2019-10-19 10:50 +0200
  Re: Show picture in window Arno Welzel <usenet@arnowelzel.de> - 2019-10-19 20:39 +0200
    Re: Show picture in window kristjanise129@gmail.com - 2020-03-13 09:46 -0700
      Re: Show picture in window Arno Welzel <usenet@arnowelzel.de> - 2020-03-14 13:11 +0100
  Re: Show picture in window R i c h m a n <he12091983@gmail.com> - 2022-10-25 03:09 -0700

csiph-web