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!!!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.