#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    How do I do a variable within a variable within a function? in the code below, $client is defined in client.inf. If I express $client (as shown), which is the same as the true directory name the script doesn't work. $client='0003';

    Warning: Unable to create '/home/httpd/html//upload/img/test.jpg': No such file or directory in /home/httpd/html/0003/upload/process_upload.php on line 8
    failed to copy file

    However, if I explicitly express $client (ex. '0003' as the client directory) it works fine.
    not using an alias under Apache, permissions are wide open during testing, and $client echos in the same script (process_upload.php4) that I receive the error message above.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><?php
    include "../client.inf";

    function do_upload($filename,$newname) {
    $file = basename($filename);
    $tmp_upload_path = "/tmp/";
    $new_file_name = "/home/httpd/html/$client/upload/core/".$newname;
    if (!copy($tmp_upload_path.$file, $new_file_name)) echo "failed to copy file<br>n";
    return;
    }
    ?>[/code]

    Any ideas?
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Try using print $client; exit; after including the file. It doesn't seem to be setting correctly.
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Oh, duh. It's in a function, Rod! I need to read more carefully...

    You need to declare $client global. Add this to your function definition:

    global $client;
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    rod k, You da' MAN! Now I can glue my hair back in place.

IMN logo majestic logo threadwatch logo seochat tools logo