Connecting Tech Pros Worldwide Forums | Help | Site Map

uploading with permissions help

sean
Guest
 
Posts: n/a
#1: Jul 17 '05
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 photoFinalDestination.

so far i have set up my groups to 'www' with read, write and execute
permissions on the folder photoFinalDestination 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_FILES should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_file()
// instead of move_uploaded_file

$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 photoFinalDestination.The version of PHP
is 4.3.3 and its running on a apache server.Any and all help
appreciated.sean


Karthik
Guest
 
Posts: n/a
#2: Jul 17 '05

re: uploading with permissions help


"sean" <someone@microsoft.com> wrote in message news:<bpda52$lrm$1@dulnain.stir.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 photoFinalDestination.
>
> so far i have set up my groups to 'www' with read, write and execute
> permissions on the folder photoFinalDestination 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_FILES should be used instead of
> // $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_file()
> // instead of move_uploaded_file
>
> $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 photoFinalDestination.The version of PHP
> is 4.3.3 and its running on a apache server.Any and all help
> appreciated.sean[/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'],"{directoryName}/".$HTTP_POST_FILES['file']['name']);
$name = $HTTP_POST_FILES['file']['name'];
print "File name is: " . $name;
unlink($HTTP_POST_FILES['file']['tmp_name']);
print "<br>File has been successfully uploaded!";
[PHP]


Hope that helps..

Karthik
Closed Thread