note 54278 added to function.ftp-put
| From: | jrisken at mn dot rr dot com | Date: | Wed, 29 Jun 2005 13:32:23 +0000 |
| Subject: | note 54278 added to function.ftp-put | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91133@lists.php.net to get a copy of this message | ||
This solution to a common problem is implied elsewhere, but I thought it might be useful to put it
all in one place (since I spent hours piecing it together!)
Sometimes a web host will open PHP sessions with a user of 'nobody'. Files created by this
user may not have the correct permissions to allow management of those files by the actual owner of
the site. The following script allows the actual owner to open access to a directory so that
'nobody' can create a file using fopen(). Then using the handle created by
'nobody', the ftp_fput() command saves the file with the correct owner. The file
'nobody' created is discarded.
<?
$connection = ftp_connect($ftpServer);
ftp_login($connection, $ftpUser, $ftpPass);
ftp_chdir($connection, $ftpDir);
// open the directory so that 'nobody' can create a temporary file
ftp_site($cn, "CHMOD 777 $ftpDir");
$new="tempFile";
@unlink($new); // just in case
$handle=fopen($new,"x");
chmod($new,0777);
fputs($handle,"a bunch of stuff...");
fclose($handle); // have to rewind
$handle=fopen("tempFile","r");
ftp_fput($connection, "finalFile", $handle, FTP_ASCII);
fclose($handle);
unlink($new);
// remove open access to the directory
ftp_site($connection, "CHMOD 755 $ftpDir")
ftp_close($connection);
?>
----
Manual Page -- http://www.php.net/manual/en/function.ftp-put.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54278
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54278&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54278&report=yes
Search -- http://master.php.net/manage/user-notes.php