Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Changing File/Folder Permission (http://www.programmingforums.org/showthread.php?t=12349)

PhilBon Jan 10th, 2007 10:42 PM

Changing File/Folder Permission
 
Hello Everyone, I was wondering if anyone knew how to change the file or Folder Permission in PHP. I have one script that for some weird reason has to have the destination Folder be set so that everyone can write to this, this is not ideal for a web file. I'm trying to make a folder with the date (where I'm getting stopped because permissions is denied. And then as you can see I want to put 3 files in there. I know it works if I change the folder to 777 but I don't want it to be. I was thinking about way could be ftp with php but that to me will take to much time to set up though I've done it before. This is also running on a mac server. Here is the code I'm working with if you want to see (not really important):
[php]
$location = "/home/username/public_html/files/";
if (file_exists($location . $month . "-" . $day . "-" . $year)){
echo "Date Already Present. If you would like to write over this, delete the previous one and then add the new one";
} else {
mkdir($location . $month . "-" . $day . "-" . $year . "/",0755);
if ($wmaupload == "1"){
//copy temp file to the folder
if (is_uploaded_file($_FILES['wma']['tmp_name'])){
move_uploaded_file($_FILES['wma']['tmp_name'],$location . $month . "-" . $day . "-" . $year . "/" . $_FILES['wma']['name']) or $wmaerror = true;
if ($wmaerror){
$error .= "The Windows Media File could not be Copied";
}
} else {
$error .= "The Windows Media File could not be uploaded";
$wmaerror = true;
}/**/
echo "wma = 1";
}
if ($mp3upload == "1"){
//copy temp file to the folder
if (is_uploaded_file($_FILES['mp3']['tmp_name'])){
move_uploaded_file($_FILES['mp3']['tmp_name'],$location . $month . "-" . $day . "-" . $year . "/" . $_FILES['mp3']['name']) or $mp3error = true;
if ($mp3error){
$error .= "The MP3 File could not be Copied";
}
} else {
$error .= "The MP3 File could not be uploaded";
$mp3error = true;
}/**/
echo "mp3 = 1";
}
if ($pdfupload == "1"){
//copy temp file to folder
if (is_uploaded_file($_FILES['pdf']['tmp_name'])){
move_uploaded_file($_FILES['pdf']['tmp_name'],$location . $month . "-" . $day . "-" . $year . "/" . $_FILES['pdf']['name']) or $pdferror = true;
if ($pdferror){
$error .= "The PDF File could not be Copied";
}
} else {
$error .= "The PDF File could not be uploaded";
$pdferror = true;
}/**/
echo "pdf = 1";
}
}
[/php]

grimpirate Jan 11th, 2007 1:41 AM

To change a file's permission in php use the chmod() function. Read more on it here
http://us2.php.net/manual/en/function.chmod.php

PhilBon Jan 11th, 2007 11:50 AM

Thanks grimpirate, now I feel like an idiot. I looked at the file ref page and totally skipped it. Sorry I'm an Idiot, but once again, Thank You :)


All times are GMT -5. The time now is 1:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC