ShootingBlanks Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/ Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 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 Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539009 Share on other sites More sharing options...
BlueSkyIS Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539012 Share on other sites More sharing options...
ShootingBlanks Posted May 12, 2008 Author Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539017 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539019 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 If file permissions are correct, then its not a permission problem. What files are them and how ure trying to read them? Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539021 Share on other sites More sharing options...
ShootingBlanks Posted May 12, 2008 Author Share Posted May 12, 2008 EDIT: - NEVERMIND!!! I needed to have the folder that the files were going into set to have "Execute" permissions. Thanks!!! Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539026 Share on other sites More sharing options...
ShootingBlanks Posted May 12, 2008 Author Share Posted May 12, 2008 EDIT: - NEVERMIND!!! I needed to have the folder that the files were going into set to have "Execute" permissions. Thanks!!! Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539036 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 What are u uploading and then launchig, executable binaries? Anyway mark the topic as solved if u aint got any other question! Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539092 Share on other sites More sharing options...
TecBrat Posted May 12, 2008 Share Posted May 12, 2008 What are u uploading and then launchig, executable binaries? ... Execute permission on a directory just means the ability to open that directory. Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539370 Share on other sites More sharing options...
Fadion Posted May 12, 2008 Share Posted May 12, 2008 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 https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539419 Share on other sites More sharing options...
ShootingBlanks Posted May 12, 2008 Author Share Posted May 12, 2008 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... Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-539442 Share on other sites More sharing options...
TecBrat Posted May 13, 2008 Share Posted May 13, 2008 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 ." Link to comment https://forums.phpfreaks.com/topic/105266-solved-chmoding-a-file-when-uploading-it/#findComment-540062 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.