note 72103 added to function.chmod
| From: | webmaster at danopia dot 5gigs dot com | Date: | Wed, 03 Jan 2007 02:20:27 +0000 |
| Subject: | note 72103 added to function.chmod | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121219@lists.php.net to get a copy of this message | ||
Thanks for your code, "imoldgreg at o2 dot co dot uk". I am using it for an instalation
script that has to CHMOD a bunch of files. I have found it faster to use the same connectino for
each, as shown below.
<?php
// Thanks to "imoldgreg at o2 dot co dot uk" for the base 'CHMOD via FTP'
script.
function chmod_open()
{
// Use your own FTP info
$ftp_user_name = 'chmod@XXXXXXXXX.com';
$ftp_user_pass = 'XXXXXXXXXX';
$ftp_root = '/';
$ftp_server = 'localhost';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
return $conn_id;
}
function chmod_file($conn_id, $permissions, $path)
{
if (ftp_site($conn_id, 'CHMOD ' . $permissions . ' ' . $ftp_root . $path) !==
false)
{
return TRUE;
}
else
{
return FALSE;
}
}
function chmod_close($conn_id)
{
ftp_close($conn_id);
}
// CHMOD the required setup files
// Connect to the FTP
$conn_id = chmod_open();
// CHMOD each file and echo the results
echo chmod_file($conn_id, 777, 'master/cache/') ? 'CHMODed successfully!' :
'Error';
echo chmod_file($conn_id, 777, 'master/files/') ? 'CHMODed successfully!' :
'Error';
echo chmod_file($conn_id, 777, 'master/store/') ? 'CHMODed successfully!' :
'Error';
echo chmod_file($conn_id, 766, 'master/config.php') ? 'CHMODed successfully!' :
'Error';
echo chmod_file($conn_id, 777, 'master/images/avatars/upload/') ? 'CHMODed
successfully!' : 'Error';
// Close the connection
chmod_close($conn_id);
?>
Here, the same FTP connection is used for each CHMOD command, making the execute time lower. This is
essential for me, since my script is also copying a bunch of files.
----
Server IP: 216.194.113.175
Probable Submitter: 70.17.45.138
----
Manual Page -- http://www.php.net/manual/en/function.chmod.php
Edit -- https://master.php.net/note/edit/72103
Del: integrated -- https://master.php.net/note/delete/72103/integrated
Del: useless -- https://master.php.net/note/delete/72103/useless
Del: bad code -- https://master.php.net/note/delete/72103/bad+code
Del: spam -- https://master.php.net/note/delete/72103/spam
Del: non-english -- https://master.php.net/note/delete/72103/non-english
Del: in docs -- https://master.php.net/note/delete/72103/in+docs
Del: other reasons-- https://master.php.net/note/delete/72103
Reject -- https://master.php.net/note/reject/72103
Search -- https://master.php.net/manage/user-notes.php