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


Groups > comp.lang.php > #18079 > unrolled thread

Show picture in window

Started byHeiko Wetteborn <heiko2912@gmail.com>
First post2019-10-19 06:50 +0200
Last post2022-10-25 03:09 -0700
Articles 7 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  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

#18079 — Show picture in window

FromHeiko Wetteborn <heiko2912@gmail.com>
Date2019-10-19 06:50 +0200
SubjectShow picture in window
Message-ID<qoe4nd$jla$1@news2.open-news-network.org>
(sorry for german language)
Hallo Leute,

ist de.comp.lang.php tot?

Ich möchte mit Hilfe des untenstehenden PHP-Scripts ein Bild in einem 
Fenster ausgeben.

Dem Script wird mittels ?bildnr=x eine Nummer (z. B. 7) übergeben, so 
dass das Script Bild Nr. 7 aus einer Liste anzeigt.

Wird eine Bildnummer übergeben, die nicht existieren kann (z. B. 
bildnr=0, wird die Meldung "Bild nicht gefunden" angezeigt.
Die Namen der Bilder werden aus der bestehenden Verzeichnisstruktur 
ausgelesen, was einwandfrei funktioniert.
Wird nun aber eine Bildnummer angegeben, die definitiv im Ordner 
vorhanden ist (z. B. bildnr=1), erhalte ich nicht die Meldung "Bild 
nicht gefunden", aber eben auch nicht das entsprechende Bild angezeigt.
Statt des anzuzeigenden Bildes sehe ich lediglich den Platzhalter für 
fehlende Grafiken (kleines Fragezeichen).

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);

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

Hier nun das Script (PHP 5.4):
<?PHP
include("function.php");
$bildnr=$_GET['bildnr'];
$dir= documentroot() . "/fotoalbum/*.jpg";
foreach (glob($dir) as $filename)
{
    $eintraege[] = $filename;
}
$picname = $eintraege[$bildnr - 1];
if (file_exists($picname))
{
    Header ("Content-type: image/jpeg");
    readfile($picname);
}
else
{
    echo "Bild nicht gefunden\r\n";
}
?>

-- 
SM-Studio bei Hildesheim: https://domicil6.de

[toc] | [next] | [standalone]


#18080

From"J.O. Aho" <user@example.net>
Date2019-10-19 10:00 +0200
Message-ID<h0vu4nFf97cU1@mid.individual.net>
In reply to#18079
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

[toc] | [prev] | [next] | [standalone]


#18081

FromJan Hansen <jhjjhjhhansen@gmail.com>
Date2019-10-19 10:50 +0200
Message-ID<20191019105022.97903934a7195039bc546c62@gmail.com>
In reply to#18079
Do it make any difference if you replace 

$dir= documentroot() . "/fotoalbum/*.jpg";

with

$dir= $_SERVER['DOCUMENT_ROOT'] . "/fotoalbum/*.jpg";



-- 
mvh Jan.
Help Microsoft stamp out piracy. Give
Linux to a friend today!

[toc] | [prev] | [next] | [standalone]


#18082

FromArno Welzel <usenet@arnowelzel.de>
Date2019-10-19 20:39 +0200
Message-ID<h113jbFmtatU1@mid.individual.net>
In reply to#18079
Heiko Wetteborn:

> (sorry for german language)
> Hallo Leute,
> 
> ist de.comp.lang.php tot?

It doesn't matter, if de.comp.lang.php is "dead" or not. This is still
an English speaking newsgroup.

[...]
> Hier nun das Script (PHP 5.4):

PHP 5.4 is *way* outdated! You should use at least PHP 7.1 and even this
version will be end of life this year. So better start at least with PHP
7.2.

Also see: <https://www.php.net/supported-versions.php>

> <?PHP
> include("function.php");

What is in function.php?

> $bildnr=$_GET['bildnr'];
> $dir= documentroot() . "/fotoalbum/*.jpg";

What does documentroot() return?

> foreach (glob($dir) as $filename)
> {
>     $eintraege[] = $filename;
> }
> $picname = $eintraege[$bildnr - 1];
> if (file_exists($picname))
> {
>     Header ("Content-type: image/jpeg");

header() and not Header() - also see:

https://www.php.net/manual/en/function.header.php

You should also get familiar with a PHP debugger like xdebug and an
editor which suports debugging.

-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#18233

Fromkristjanise129@gmail.com
Date2020-03-13 09:46 -0700
Message-ID<da4a7af8-72ca-46f3-9487-2f8f93108280@googlegroups.com>
In reply to#18082
pühapäev, 20. oktoober 2019 10:37.01 UTC+3 kirjutas Luuk:
> On 19-10-2019 20:39, Arno Welzel wrote:
> > Heiko Wetteborn:
> > 
> 
> >>      Header ("Content-type: image/jpeg");
> > 
> > header() and not Header() - also see:
> > 
> > https://www.php.net/manual/en/function.header.php
> > 
> 
> $ cat function.php
> <?php
> 
> function Test($i) {
>   return $i+1;
> }
> 
> function test($i) {
>   return $i+2;
> }
> 
> echo 1, Test(1),test(1);
> $ php -l function.php
> PHP Fatal error:  Cannot redeclare test() (previously declared in 
> function.php:3) in function.php on line 9
> 
> Fatal error: Cannot redeclare test() (previously declared in 
> function.php:3) in function.php on line 9
> Errors parsing function.php
> $
> 
> 
> Function names are case insensitive.
> 
> But it is better to follow the case as it is mentioned in the manual.
> 
> I could not find a special link to this in the manual, the most relevant 
> page about this seems to be:
> https://www.php.net/manual/en/userlandnaming.rules.php
> 
> 
> -- 
> Luuk

Hello....
Are you Andres ?



Kristjan Robam

[toc] | [prev] | [next] | [standalone]


#18242

FromArno Welzel <usenet@arnowelzel.de>
Date2020-03-14 13:11 +0100
Message-ID<hd3vvtFc0u3U1@mid.individual.net>
In reply to#18233
kristjanise129@gmail.com:

> pühapäev, 20. oktoober 2019 10:37.01 UTC+3 kirjutas Luuk:
[...]
>> I could not find a special link to this in the manual, the most relevant 
>> page about this seems to be:
>> https://www.php.net/manual/en/userlandnaming.rules.php

I didn't get the original post by kirjutas Luuk on my servers, so I
reply to this.

See PHP Standards Recommendations (PSR): <https://www.php-fig.org/psr/>



-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#19139

FromR i c h m a n <he12091983@gmail.com>
Date2022-10-25 03:09 -0700
Message-ID<3398ca5e-7327-4341-8687-f2603965ac26n@googlegroups.com>
In reply to#18079
No kiddin' !!!!!!!!!!!!!

Enter to address bar: c:// and choose your file location.



My telephone number: +372 56330687

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web