Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [PHP] Wyświetlanie grafiki z serwera danego dnia, badź innego pliku
ShamY
post
Post #1





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Witam, nie wiedziałem jak nazwac dokładnie temat, wiec opisze sprawe dokladniej.
szukam dość prostego skryptu, który będzie wyświetlał żdjęcia na dzisiejszy i jutrzejszy dzień, zdjęcie na serwerze będzie w formacie DDMMYYYY i jesli z tym nie ma problemu to nie mam pojęcia jak napisać część że jak tego pliku np. 27032014.png nie będzie na serwerze, to wyświetli się grafika o nazwie "brak.jpg"

Ktoś by wiedział jak to wykonać lub znaleźć gotowy? Ja szuałem, ale niestety nic.

Ten post edytował ShamY 27.03.2014, 15:04:02
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Tu jest gotowe rozwiązanie: http://pl1.php.net/file_exists
Go to the top of the page
+Quote Post
ShamY
post
Post #3





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


  1. $filename = '/path/to/foo.txt';
  2.  
  3. if (file_exists($filename)) {
  4. echo "The file $filename exists";
  5. } else {
  6. echo "The file $filename does not exist";


Filename mam podać ściżzke do pliku? Np: "adres/images/folder/<?php echo date("Ymd");?>.png" (IMG:style_emoticons/default/questionmark.gif)

Ten post edytował ShamY 27.03.2014, 17:26:12
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Tak, ale:
  1. $filename="adres/images/folder/".date("Ymd").".png";
Go to the top of the page
+Quote Post
ShamY
post
Post #5





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


  1. <?php
  2. $filename="/images/folder/".date("Ymd").".png";
  3.  
  4. if (file_exists($filename)) {
  5. echo '<img src="$filename">';
  6. } else {
  7. echo '<img src="/images/folder/brak.png">';
  8. }
  9. ?>


mam tak i wyswietla się tylko "brak.png" pomimo iż na serwerze jest plik o nazwie "20140327.png"
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


A ścieżka do tego pliku na pewno jest poprawna (względem pliku php)?
Go to the top of the page
+Quote Post
ShamY
post
Post #7





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Gdy linijkę 5 przekopiuję na 7 to działa więc wychodzi na to, że file_exists zwraca że takiego pliku niema.
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Sprawdź czy masz wyłączone safe_mode na serwerze.
  1. var_dump(ini_get('safe_mode'));
Go to the top of the page
+Quote Post
ShamY
post
Post #9





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Nie
  1. bool(false)


Ten post edytował ShamY 27.03.2014, 18:49:56
Go to the top of the page
+Quote Post
trueblue
post
Post #10





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Masz wyłączone, bo false.
Włącz.
Pracujesz na localhost, czy zdalnym serwerze?
Go to the top of the page
+Quote Post
ShamY
post
Post #11





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Na cba.pl, jak mam to zrobić?
Go to the top of the page
+Quote Post
trueblue
post
Post #12





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Na początku kodu PHP:
  1. ini_set("safe_mode","1");

lub w pliku php.ini umieszczonym na serwerze:
safe_mode = On

Ale nie wiem czy to zadziała.
Go to the top of the page
+Quote Post
ShamY
post
Post #13





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Niestety, jedno, ani drugie nie działa... Jest jakiś inny sposób?
Go to the top of the page
+Quote Post
trueblue
post
Post #14





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Pisać od adminów cba.
Go to the top of the page
+Quote Post
ShamY
post
Post #15





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


No ale oprócz tego? Jakaś okrężna droga na umieszczanie tego obrazka?
Go to the top of the page
+Quote Post
trueblue
post
Post #16





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Spróbuj tak:
  1. if(is_file($filename)){
  2. }
  3. else{
  4. }


Ten post edytował trueblue 27.03.2014, 19:17:08
Go to the top of the page
+Quote Post
ShamY
post
Post #17





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Nie bardzo rozumiem
  1. if (file_exists($filename)) {
  2. }
  3. echo '<img src="$filename">';
  4. } else {
  5. echo '<img src="/images/folder/brak.png">';
  6. }


tak?
Go to the top of the page
+Quote Post
trueblue
post
Post #18





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Nie. Podałem przykład z funkcją is_file()
Go to the top of the page
+Quote Post
ShamY
post
Post #19





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Przy
  1. if (is_file($filename)) {
  2. echo '<img src="$filename">';
  3. } else {
  4. echo '<img src="/images/folder/brak.png">';
  5. }

też wyświetla się "brak".
Go to the top of the page
+Quote Post
trueblue
post
Post #20





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


A tak?
  1. $filename="/images/folder/".date("Ymd").".png";
  2. if (file_exists($filename)) {
  3. echo '<img src="$filename">';
  4. } else {
  5. echo '<img src="/images/folder/brak.png">';
  6. }
Go to the top of the page
+Quote Post
ShamY
post
Post #21





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Jest :"brak.png" ale jak przekopiowalem linijkę z 4 na 6 to w pasku adresu jest: "adres strony/$filename"
Go to the top of the page
+Quote Post
IProSoft
post
Post #22





Grupa: Zarejestrowani
Postów: 479
Pomógł: 97
Dołączył: 6.09.2011
Skąd: php.net :)

Ostrzeżenie: (0%)
-----


Zamiast:
  1. echo '<img src="$filename">';

wstaw
  1. echo '<img src="' . $filename . '">';
Go to the top of the page
+Quote Post
ShamY
post
Post #23





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Teraz filename dobrze się wyświetla, ale jak jest na swoich miejscach to nadal źle...

Ten post edytował ShamY 27.03.2014, 19:52:58
Go to the top of the page
+Quote Post
trueblue
post
Post #24





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Na pewno 20140327.png leży w tym samym miejscu co brak.png?
Czy rozszerzenie nie zawiera wielkich liter?
Go to the top of the page
+Quote Post
ShamY
post
Post #25





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Tak w tym samym miejscu są
(IMG:http://wstaw.org/m/2014/03/27/ftp_png_300x300_q85.jpg)

w całej scieżce do obu plików są małe litery.
Go to the top of the page
+Quote Post
trueblue
post
Post #26





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. $filename="/images/folder/".date("Ymd").".png";
  2. if (file_get_contents($filename)!==false) {
  3. echo "<img src=\"".$filename."\">";
  4. } else {
  5. echo '<img src="/images/folder/brak.png">';
  6. }

Może tak, choć bardzo brzydkie rozwiązanie:)



Ten post edytował trueblue 27.03.2014, 20:11:22
Go to the top of the page
+Quote Post
ShamY
post
Post #27





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Niestety, po zamianie linijek działa, a przed nie...
Go to the top of the page
+Quote Post
trueblue
post
Post #28





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Po zamianie linijek 3 i 5?
Zerknij, bo wcześniej pomyliłem warunek, później zmieniłem.

Ten post edytował trueblue 27.03.2014, 20:21:12
Go to the top of the page
+Quote Post
ShamY
post
Post #29





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Teraz zrobilem jeszcze raz i nadal to samo. Przy zmianie 3 na 5 wyświetla się grafika 20140327.png...

Zmieniłem na:
  1. <?php
  2. $filename="http://adres/images/folder/".date("Ymd").".png";
  3. if (file_get_contents($filename)!==false) {
  4. echo '<img src="http://adres/images/folder/".date("Ymd").".png">';
  5. } else {
  6. echo '<img src="http://adres/images/folder/brak.png">';
  7. }
  8. ?>

to wyświetla się taki mniejszy obrazek z ikonką zlamanej fotki i jego adres to: "http://adres/images/folder/", czyli teraz nie czyta ".date("Ymd")." w img src.

Ten post edytował ShamY 27.03.2014, 20:42:34
Go to the top of the page
+Quote Post
trueblue
post
Post #30





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. echo '<img src="http://adres/images/folder/"'.date("Ymd").'".png">';
Go to the top of the page
+Quote Post
ShamY
post
Post #31





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Ehh, chyba moja radość była przedwczesna, nadal nie chce samo się rozkodować "Ymd" i jest obrazek z ikonką złamanej fotki.

Ten post edytował ShamY 27.03.2014, 20:48:51
Go to the top of the page
+Quote Post
IProSoft
post
Post #32





Grupa: Zarejestrowani
Postów: 479
Pomógł: 97
Dołączył: 6.09.2011
Skąd: php.net :)

Ostrzeżenie: (0%)
-----


Co wyświetli Ci kod:
  1. echo '/images/folder/'.date("Ymd").'.png';

?
Go to the top of the page
+Quote Post
ShamY
post
Post #33





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


No wyświetla ścieżke do pliku...

Działa, ale gdy nazwa pliku jest np. 20140330.png to wyświetla ja mimo iż powinno być wyświetlane na dzień 27
Go to the top of the page
+Quote Post
Turson
post
Post #34





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Jeżeli
  1. echo date("Ymd");

pokazuje ci inny dzień, to widocznie czas serwera jest zły
Go to the top of the page
+Quote Post
ShamY
post
Post #35





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Jak zmieniam nazwę pliku na 28, 29 czy inne z dwadzieścia to jest to samo czyli czas serwera jest ok
Go to the top of the page
+Quote Post
IProSoft
post
Post #36





Grupa: Zarejestrowani
Postów: 479
Pomógł: 97
Dołączył: 6.09.2011
Skąd: php.net :)

Ostrzeżenie: (0%)
-----


Napisz co wyświetla Ci :
  1. echo date("Ymd");

Dokładnie co wyświetla, a nie co się dzieje jako coś tam zmienisz..

Ten post edytował IProSoft 27.03.2014, 22:55:57
Go to the top of the page
+Quote Post
ShamY
post
Post #37





Grupa: Zarejestrowani
Postów: 111
Pomógł: 0
Dołączył: 11.07.2013

Ostrzeżenie: (0%)
-----


Wyświetla się dzisiejsza data (20140327)

Działa!
Dodałem -1 przed końcówką png i teraz wyświetla dobry obrazek (IMG:style_emoticons/default/smile.gif)

Dzięki wszystkim za pomoc, każdemu leci pomógł (IMG:style_emoticons/default/wink.gif)

Ten post edytował ShamY 27.03.2014, 23:32:16
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.09.2025 - 13:05