file upload and file permissions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

file upload and file permissions

Post by andylyon87 »

Please please help, I have tried this code, its real basic because Ive never done it before, but if it works it will be going on my site.

Code: Select all

if($File){
print("file name: $File_name<P>\n");
print("file size: $File_size<P>\n");
if(copy($File_name, "users/$File_name"))&#123;
          print("file uploaded\n");
          &#125;else&#123;
          print("File not copied\n");
          &#125;
          unlink($File);
&#125;
  print("upload a file:");
  print("<form action=fileupload.php method=post enctype=multipart/formdata>\n");
  print("file<input type=file name="File" size=20><BR>\n");
  print("<input type=submit name=submit value=Submit!></form>\n");
The problem is it keeps coming up with permission denied errors and I was wonderin where I can change folder and file permissions, that is if there isn' any other problems
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

chmod 777
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

To expand a bit, you should make an upload directory with php mkdir(): that way php will be the owner of the folder and can still write to it if its set to something more secure such as 755.

You'll probably need to chmod the parent dir 777 (with your ftp program/telnet), create the new folder inside that with php, then chmod the parent back to 755 or whatever.

A dirinfo command in your ftp program can help to see what's going on. You'll notice that files/folders created with your ftp program have a different UID to those dreated with php (which often has the owner/group nobody/nobody).
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

thanks for explaining for me

i was feeling a lil' lazy :?
Post Reply