
April 8th, 2008, 02:42 PM
|
|
Contributing User
|
|
Join Date: Nov 2007
Posts: 83
Time spent in forums: 6 h 23 m 30 sec
Reputation Power: 1
|
|
How to loop through?
How to loop through the script to make it work better?
I may have three or more folders to set permissions on, but have to copy and paste the same script three or more times to run it.
How to loop to set permissions per folder?
PHP Code:
<?php
$host = 'www.example.com'; // host (website) that contains the folder you want to change
$user = '******';
$password = '******';
$folder = '/folder/nestedfolder/';
//Set the next folder to set permissions on
$folder2 = '/folder/nestedfolder2/';
$mod = '0755';
// connect to FTP site
$conn = ftp_connect("$host");
if (!$conn)
{
echo 'Error: Could not connect to ftp server';
exit;
}
// log in to FTP site
@ $result = ftp_login($conn, $user, $password);
if (!$result)
{
echo "Error: Could not log on as $user";
ftp_quit($conn);
exit;
}
//HOW TO LOOP FROM HERE FOR $folder2 or any other variables?
// try to change the permissions on the directory
if (ftp_site($conn, 'CHMOD '.$mod.' '.$folder)) {
echo "Successfully changed permissions";
}
else {
echo "There was a problem changing the permissions";
ftp_quit($conn);
exit;
}
// close the connection
ftp_close($conn);
?>
|