ballouta Posted April 29, 2009 Share Posted April 29, 2009 Hello I am trying to check if an inserted name for a directory exists or not. I wrote: <?php $gname = $_POST['name']; $filename = '/home/farid/public_html/images/galleries/$gname'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?> I already created a folder in this location: images/galleries/ballouta but the output is: The file /home/farid/public_html/images/galleries/$gname does not exist where is the problem? Please help thank you Link to comment https://forums.phpfreaks.com/topic/156160-solved-file_exists-function-help/ Share on other sites More sharing options...
wildteen88 Posted April 29, 2009 Share Posted April 29, 2009 variables are not parsed within single quotes, You should use $filename = '/home/farid/public_html/images/galleries/'.$gname; or $filename = "/home/farid/public_html/images/galleries/$gname"; Link to comment https://forums.phpfreaks.com/topic/156160-solved-file_exists-function-help/#findComment-822059 Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 I just hate interpolating variables. It looks so tacky. Link to comment https://forums.phpfreaks.com/topic/156160-solved-file_exists-function-help/#findComment-822062 Share on other sites More sharing options...
ballouta Posted April 29, 2009 Author Share Posted April 29, 2009 thank you wildteen88 Link to comment https://forums.phpfreaks.com/topic/156160-solved-file_exists-function-help/#findComment-822065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.