-4

Can someone tell me what is wrong with this code?

<?php
    $user = $fgmembersite->UserFullName();
    $handle = opendir('/users/$user/');
?>

This is the error message:

opendir(/app/$user/) [function.opendir]: failed to open dir: No such file or directory in
Josh
  • 2,835
  • 1
  • 21
  • 33

3 Answers3

3

Double quotes to evaluate variables

$handle = opendir("/users/$user/");

What is the difference between single-quoted and double-quoted strings in PHP?

Community
  • 1
  • 1
Mike B
  • 31,886
  • 13
  • 87
  • 111
  • 1
    "doesn't work" isn't in a developer's vocabulary. You'll have to be more specific. – Mike B Mar 23 '12 at 17:11
  • then the directory doesn't exist, OR if it does then you are probably looking at a permissions issue – Murray McDonald Mar 23 '12 at 17:13
  • 1
    `/users` is going to be relative to the root. What you probably want is `opendir("users/$user/")` – wanovak Mar 23 '12 at 17:13
  • nevermind I figured it out and your solution helped me a lot wanovak. Thanks :) – Josh Mar 23 '12 at 17:16
  • yes the directory didn't exist because I had a "/" which pointed it to the root directory of my server not the directory I was working in – Josh Mar 23 '12 at 17:21
1

In single quotes $user will not be interpreted as a variable - in double quotes it will be try opedir("/users/$user")

Murray McDonald
  • 631
  • 4
  • 5
1

try this:

$handle = opendir("/users/$user/");
magicianiam
  • 1,474
  • 7
  • 33
  • 70