CHMOD 600 not 644 - help!

Discussion in 'PHP' started by freebie, Nov 12, 2007.

  1. #1
    This one is proving a little tricky!

    I use php upload to move an image from PC to server. Trouble is when image uploaded it defaults CHMOD to 600 - meaning no-one can access it.

    I am using following code:

    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

    $file_dir = "/path/to/server/htdocs";

    foreach($_FILES as $file_name => $file_array) {
    if (is_uploaded_file($file_array['tmp_name'])) {
    move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy");
    }
    }
    chmod ('$file_dir/$file_array[name]', 0755);


    Of course I have replaced the actually $file_dir above to protect username but even though I have left the CHMOD until the end I receive error even though image uploads to server fine:

    Warning: chmod() [function.chmod]: No such file or directory in /path/to/server/htdocs/entry.php on line 14


    Does anyone have any ideas? :confused:

    Thanks!
     
    freebie, Nov 12, 2007 IP
  2. bquast

    bquast Active Member

    Messages:
    275
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    78
    #2
    also uid is needed in their as well look at the php manual, works wonders.. cannot remember why it has been to long since I touched php but yeah..

    maybe your path is wrong, you don't need the exact path from the top to it, just from where the script is run to the file, so that could be the other possible error.
     
    bquast, Nov 12, 2007 IP
  3. freebie

    freebie Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I know the path is correct because the image is uploading fine - it's just the CHMOD that's the problem. I've also tried:

    chmod ('$file_array[name]', 0755);

    But this brings up the same error!

    Any ideas??

    Thanks,
    CC
     
    freebie, Nov 13, 2007 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    variables do not work inside single quotes ...
     
    krakjoe, Nov 13, 2007 IP
  5. freebie

    freebie Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks!

    The double quotes worked fine

    Thanks,
    CC
     
    freebie, Nov 13, 2007 IP