Friday, September 22, 2006

PHP and Uploading files.

The past couple of days I've been working on a solution to upload files to my web host using PHP and an HTML form.

I have found out some interesting information that I thought I would share.

I'm sure anyone that has used PHP before knows that when you upload a file you're going to use the move_uploaded_file() function. I have found that when you use this function on a Linux / Unix based web host that are some issues when in comes to setting file permissions.

Normally you upload the files to a directory that has read / write permissions (666 / 664). Then you simply change the permissions on the file by running the chmod($file, 0644) so everyone can read the file. I tried using these menthods and different have to much success.

Then I tried to upload the files to a directory that had read / write and execute permissions (777) and it work but I felt that having a directory with permissions like that on a web server is just asking for trouble. Also, I found that if you uploaded a file to a directory with those permissions and then run the chmod() function on the file that your ftp client can no manipulate the file (delete, rename or change permissions).

I knew there had to be a better way to upload these files and not have to deal with file permissions. Well PHP has some FTP functions and one of those functions, ftp_put(), allows you to upload files.

I'll post the source code later. If you have any suggestion / comments please feel free to give me some feed back.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home