By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

uploading with permissions help

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"sean" <so*****@microsoft.com> wrote in message news:<bp**********@dulnain.stir.ac.uk>...
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


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
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.