Jump to content

[SOLVED] CHMOD'ing a file when uploading it?


ShootingBlanks

Recommended Posts

Hello.

 

I created a standard form for people to upload files to my web server from.  The problem is that when the files get uploaded, they are not readable.  The FOLDER on the server is CHMOD'd to "744", but the FILES get uploaded as "600" (not readable)...

 

I would like to know how to get a file uploaded as "744" when using the standard "move_uploaded_file" command?...

 

Thanks!!!

 

 

After uploading with move_uploaded_file() u certainly have the filename in a variable. So run a chmod() on it:

 

<?php
$file = 'folder/myfile.txt';
chmod($file, 0744);
?>

 

EDIT: Oh and by the way, move_uploaded_file() is a function, not a command :P

personally, i have never been able to manage it during the upload. i have seen it done via PHP FTP, but not directly in the upload script. my solution has been to run a cron job that chmod's all files in a specified directory on a regular basis. i'd love to find away around this problem myself, without having to change the user under whom php and/or apache run under.

 

edit to add: At least for me, the problem has been that PHP runs under a different user than the person who owns the account where the file is uploaded. My experience has been that I can upload a file to a directory, but chmod() fails to do anything. thus my crontab to chmod files on a regular basis.

At least for me, the problem has been that PHP runs under a different user than the person who owns the account where the file is uploaded. My experience has been that I can upload a file to a directory, but chmod() fails to do anything. thus my crontab to chmod files on a regular basis.

That's the problem I'm having!  I used the "chmod" function, and if I log into my FTP server, I can see that the permissions on the file are what I want them to be.  However, the file still isn't readable for whatever reason!...

 

What is this "crontab" thing that you did?  Is it easy?  Easy enough for a PHP noob like me???  ;)

 

Thanks!

Actually, BlueSkyIS ure right. From the manual:

 

Note: The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.

 

Im not an expert here, so ill let others talk, but what im thinking is that files uploaded programatically, are owned by the current user, thus havinig access to chmod them.

What are u uploading and then launchig, executable binaries? ...

 

Execute permission on a directory just means the ability to open that directory.

 

First we are talking about files. Second just a simple search and i found this in wikipedia:

 

The execute permission, which grants the ability to execute a file. This permission must be set for executable binaries in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).

 

To open a directory, u just need "read" permissions.

To open a directory, u just need "read" permissions.

 

I dunno.  I had "read" permissions on the directory, and it wasn't opening the files.  I added "execute" permissions, and it worked fine.  The files were just .jpgs and .docs.  That's it...

 

 

To open a directory, u just need "read" permissions.

 

according to http://staff.washington.edu/dgrimmer/walkthrough.htm, my experience and SB's post above,

 

"To open a directory, you need to set the execute bit (an open is to execute the directory).

$ chmod 755 <directory>  results in  'drwxrxrx' when listed with ls -l ."

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.