Re: [PHP] file_exists() question
what does $annrow[id] return? I HAVE found that I have to refer to a file when using file_exists() from / so file_exists(/path/to/me/cherpdocs/filename.doc) for it to work right. Jim - Original Message - From: Charles Kline [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, March 08, 2003 1:10 PM Subject: [PHP] file_exists() question Can anyone tell me why this code does not return true when the file in the directory cherpdocs/ with the file (which I see as being there) does exist? if(file_exists('cherpdocs/$annrow[id].doc')){ echo br /a href=\cherpdocs/$annrow[id].doc\Funding details paper/a; } This is a path relative to the file calling it, should it be otherwise? Thanks Charles -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists() question
because you can't directly use the $annrow[id] within single quotes, you should use double quotes to do so. file_exists(cherpdocs/$annrow[id].doc) or file_exists('cherpdocs/'.$annrow[id].'.doc') or file_exists(cherpdocs/.$annrow[id]..doc) Note: i heared it's prefered to always use the . when including variables within strings. Regards, Khalid Al-Kary http://creaturesx.ma.cx/kxparse/ Can anyone tell me why this code does not return true when the file in the directory cherpdocs/ with the file (which I see as being there) does exist? if(file_exists('cherpdocs/$annrow[id].doc')){ echo br /a href=\cherpdocs/$annrow[id].doc\Funding details paper/a; } This is a path relative to the file calling it, should it be otherwise? Thanks Charles -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists() question
You will probably need to use file_exists(cherpdocs/{$annrow['id']}.doc) you could also use file_exists('cherpdocs/' . $annrow['id'] . '.doc') You should use single quotes to identify your element in an array, otherwise PHP will try to use it as a constant first. Jason On Sat, 2003-03-08 at 14:40, Khalid El-Kary wrote: because you can't directly use the $annrow[id] within single quotes, you should use double quotes to do so. file_exists(cherpdocs/$annrow[id].doc) or file_exists('cherpdocs/'.$annrow[id].'.doc') or file_exists(cherpdocs/.$annrow[id]..doc) Note: i heared it's prefered to always use the . when including variables within strings. Regards, Khalid Al-Kary http://creaturesx.ma.cx/kxparse/ Can anyone tell me why this code does not return true when the file in the directory cherpdocs/ with the file (which I see as being there) does exist? if(file_exists('cherpdocs/$annrow[id].doc')){ echo br /a href=\cherpdocs/$annrow[id].doc\Funding details paper/a; } This is a path relative to the file calling it, should it be otherwise? Thanks Charles -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Add photos to your e-mail with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail -- Jason Sheets [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists() question
At 22:40 08.03.2003, Khalid El-Kary said: [snip] because you can't directly use the $annrow[id] within single quotes, you should use double quotes to do so. file_exists(cherpdocs/$annrow[id].doc) or file_exists('cherpdocs/'.$annrow[id].'.doc') or file_exists(cherpdocs/.$annrow[id]..doc) Note: i heared it's prefered to always use the . when including variables within strings. [snip] Hmm - that's a bit different. 1) You can't use variables in singlequoted strings - these don't get parsed by PHP. 2) You can absolutely use variables in doublequoted strings as these do get parsed. 3) Array indices and object references must be enclosed in curly brackets when used within double quotes to tell PHP what the variable and what the string text is. Example: cherpdocs/$annrow[id].doc == doesn't work correctly cherpdocs/{$annrow['id']}.doc == will work cherpdocs/$object-docname.doc == will not work cherpdocs/{$object-docname}.doc == will work Note that you should quote non-numeric array indices to allow PHP to recognize it's not a defined value. Omitting quotes for index data would trigger a warning (something like 'using unknown identifier id, assuming id'). -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists() question
on 09/03/03 8:10 AM, Charles Kline ([EMAIL PROTECTED]) wrote: if(file_exists('cherpdocs/$annrow[id].doc')){ echo br /a href=\cherpdocs/$annrow[id].doc\Funding details paper/a; } This is a pretty simple debugging type query, so: First things first, make sure that $annrow[id] is what you expect, by echoing it to the screen. ? echo $annrow[id] . br /; ? Then your file_exists() line has to use double quotes, because you're using a variable: file_exists(cherpdocs/$annrow[id].doc) Or better still, clarify exactly what you want by using {braces} or .'s file_exists(cherpdocs/{$annrow[id]}.doc) Or: file_exists(cherpdocs/ . $annrow[id] . .doc) Same applies to your echo line. Summary, I think you can save yourself a little grief by making the following changes to your code. Personally, I prefer wrapping all vars in {braces} if inside a string. It also includes some minor debugging code, so that you can hunt down the issue. ? $file = cherpdocs/{$annrow[id]}.doc if(file_exists($file)) { echo br /a href=\{$file}\Funding details paper/a; } else { echo The file {$file} did not exist; } ? Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php