[PHP] file_exist pakt geen variabele in een functie

Pagina: 1
Acties:
  • 44 views sinds 30-01-2008

  • Cartman!
  • Registratie: April 2000
  • Niet online
Ik ben bezig een foto album te maken, gewoon omdat ik het leuk vind met php te klooien en proberen het te leren. Het album laat de huidige pic ($id) zien uit het huidige album ($album). Eronder zitten knopjes die 5 terug, 1 terug, 1 vooruit,, 5 vooruit aangeven. Ik wil deze zo laten werken dat er eerst gekeken wordt of het huidige id + 5 wel bestaat. Als deze niet bestaat wordt de link niet actief zodat er geen mogelijkheid is om op een dode link te komen.

Met file_exist ben ik erachter gekomen dat het mogelijk is. Ik heb er een functie voor gemaakt die alles checkt :

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function check() 
{
    global $check_fback;
    global $check_back;
    global $check_next;
    global $check_fnext;
    global $id_fback;
    global $id_back;
    global $id_fnext;
    global $id_next;
    global $album;
    if(file_exists($check_fback)) { print ("<p class=text><a href=\"photo.php?album=$album&amp;id=$id_fback\">&lt;&lt;</a>"); }
    else { print ("<p class=text>&lt;&lt;"); }
    print ("&nbsp;-&nbsp;");
    if(file_exists($check_back)) { print ("<a href=\"photo.php?album=$album&amp;id=$id_back\">&lt;</a>"); }
    else { print ("&lt;"); }
    print ("&nbsp;-&nbsp;");
    if(file_exists($check_next)) { print ("<a href=\"photo.php?album=$album&amp;id=$id_next\">&gt;</a>"); }
    else { print ("&gt;"); }
    print ("&nbsp;-&nbsp;");
    if(file_exists($check_fnext)) { print ("<a href=\"photo.php?album=$album&amp;id=$id_fnext\">&gt;&gt;</a></p>"); }
    else { print ("&gt;&gt;</p>"); }
}


de variabelen staan voor de functie :

PHP:
1
2
3
4
5
6
7
8
9
10
$id = (int)$_GET['id'];
$album = (int)$_GET['album'];
$id_back = $id - 1;
$id_fback = $id - 5;
$id_next = $id + 1;
$id_fnext = $id + 5;
$check_fback = '/images/$album/$id_fback.jpg'; //controleren of file wel bestaat
$check_back = '/images/$album/$id_back.jpg'; //controleren of file wel bestaat
$check_next = '/images/$album/$id_next.jpg'; //controleren of file wel bestaat
$check_fnext = '/images/$album/$id_fnext.jpg'; //controleren of file wel bestaat


maar als ik de funcie oproep dan krijg ik alleen niet werkende links omdat blijkbaar de gecheckte files niet bestaan, terwijl deze wel bestaan. Als ik bij de variabelen een statisch iets invul, dan werkt het wel. Maar ik wil alles natuurlijk dynamisch, logisch :)

ik ben er dus achter dat de file_exist dus niet om gaat met de variabelen $album, $id_fback, $id_back, $id_next en $id_fnext. Mijn vraag is natuurlijk hoe dit op te lossen is. Op php.net kon ik niks vinden over variabelen in combinatie met file_exist. google boodt geen uitkomst :'(

iemand die me uit de brand kan helpen ?

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 13:17

crisp

Devver

Pixelated

Misschien als je je $check_ variabelen anders vult, bv
PHP:
1
$check_fback = "/images/$album/$id_fback.jpg"; // dubbele quotes zodat $album en $id geparsed worden

of:
PHP:
1
$check_fback = '/images/'.$album.'/'.$id.'_fback.jpg';

Intentionally left blank


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 12:28

Janoz

Moderator Devschuur®

!litemod

Trouwens.. Je kunt ook parameters aan je functies meegeven hoor ;)

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • Cartman!
  • Registratie: April 2000
  • Niet online
ik ben er nu achtergekomen wat de fout is door
PHP:
1
print ("$check_fback");


ik krijg dan de url : images/1/2.jpg terwijl dit images/1/002.jpg moet zijn.

ik heb met :

PHP:
1
$b = $id; while (strlen ($b) < 3){ $b = "0" . $b; }

er eerder voor gezorgd dat elk $id uit 3 getallen bestaat. Maar blijkbaar pakt ie de 0-en dus niet mee in de url. Dat is dus het probleem, en niet dat hij de variabelen niet pakt... :{

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

goed op verzoek

Doet iets met Cloud (MS/IBM)


Dit topic is gesloten.