uploading with permissions help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sean

    uploading with permissions help

    hi

    Firstly i am working with php in an enviroment that supports unix-like
    permission in an accademic environment.

    The problem is enabling my script to upload a image file to my home folder,
    called say photoFinalDesti nation.

    so far i have set up my groups to 'www' with read, write and execute
    permissions on the folder photoFinalDesti nation from within unix

    my php script is the template from php.net obviously modified for my
    filenames and stuff.

    <?php
    // In PHP earlier then 4.1.0, $HTTP_POST_FILE S should be used instead of
    // $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_fil e()
    // instead of move_uploaded_f ile

    $uploaddir = '/var/www/uploads/';
    $uploadfile = $uploaddir. $_FILES['userfile']['name'];

    print "<pre>";
    if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    print "File is valid, and was successfully uploaded. ";
    print "Here's some more debugging info:\n";
    print_r($_FILES );
    } else {
    print "Possible file upload attack! Here's some debugging info:\n";
    print_r($_FILES );
    }
    print "</pre>";

    ?>I can definatly upload to the temprary file on the server but i cannot
    'move_uploaded_ file()' to my folder photoFinalDesti nation.The version of PHP
    is 4.3.3 and its running on a apache server.Any and all help
    appreciated.sea n


  • Karthik

    #2
    Re: uploading with permissions help

    "sean" <someone@micros oft.com> wrote in message news:<bpda52$lr m$1@dulnain.sti r.ac.uk>...[color=blue]
    > hi
    >
    > Firstly i am working with php in an enviroment that supports unix-like
    > permission in an accademic environment.
    >
    > The problem is enabling my script to upload a image file to my home folder,
    > called say photoFinalDesti nation.
    >
    > so far i have set up my groups to 'www' with read, write and execute
    > permissions on the folder photoFinalDesti nation from within unix
    >
    > my php script is the template from php.net obviously modified for my
    > filenames and stuff.
    >
    > <?php
    > // In PHP earlier then 4.1.0, $HTTP_POST_FILE S should be used instead of
    > // $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_fil e()
    > // instead of move_uploaded_f ile
    >
    > $uploaddir = '/var/www/uploads/';
    > $uploadfile = $uploaddir. $_FILES['userfile']['name'];
    >
    > print "<pre>";
    > if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    > print "File is valid, and was successfully uploaded. ";
    > print "Here's some more debugging info:\n";
    > print_r($_FILES );
    > } else {
    > print "Possible file upload attack! Here's some debugging info:\n";
    > print_r($_FILES );
    > }
    > print "</pre>";
    >
    > ?>I can definatly upload to the temprary file on the server but i cannot
    > 'move_uploaded_ file()' to my folder photoFinalDesti nation.The version of PHP
    > is 4.3.3 and its running on a apache server.Any and all help
    > appreciated.sea n[/color]



    Hey sean,

    here is what i did to get my file upload to work...
    first i check to see if all the parameters are correct...like file
    size and type.

    and then to actually copy the file to the destination directory i use
    the following piece of code...

    [PHP.
    copy($HTTP_POST _FILES['file']['tmp_name'],"{directoryNam e}/".$HTTP_POST_FI LES['file']['name']);
    $name = $HTTP_POST_FILE S['file']['name'];
    print "File name is: " . $name;
    unlink($HTTP_PO ST_FILES['file']['tmp_name']);
    print "<br>File has been successfully uploaded!";
    [PHP]


    Hope that helps..

    Karthik

    Comment

    Working...