note 42379 added to function.copy

From: Date: Fri, 14 May 2004 00:42:20 +0000
Subject: note 42379 added to function.copy
Groups: php.notes 
Request: Send a blank email to php-notes+get-69590@lists.php.net to get a copy of this message
And another submission, related to recursive mkdir... Iin case the Apache's usergroup doesn't allow you to opendir() the directory created EVEN WITH 0777 permissions (drwxrwxrwx) - it's specified on some functions that: "When safe mode is enabled, PHP checks whether the directory in which you are about to operate has the same UID (owner) as the script that is being executed." Still you can use ftp connection to create that directory, BUT, since you connect with your user/password, that folder will be yours (user/group) and Apache ('s usergroup) (through PHP's chmod()) can't change permissions. So, you will have to use a ftp_chmod() function to set 0777 on that folder. BUT, ftp_chmod() is available only for PHP5. Therefore, you will need to use some trick, as Loup_iotte at pagesperso dot org said on ftp_chmod()'s function.manual. So, in hope that someone will need this thing after all and helping that person to keep his cool (and not wanting to kick something for not knowing "why isn't that working?"), here's the code: <?php // it copies $wf to $wto function copy_dirs($conn_id, $wf, $wto) { if (!file_exists($wto)) { @ftp_mkdir($conn_id, $wto); $chmod_cmd = "CHMOD 0777 ".$wto; $chmod = ftp_site($conn_id, $chmod_cmd); } $arr=ls_a($wf); foreach ($arr as $fn) { if($fn) { $fl=$wf."/".$fn; $flto=$wto."/".$fn; if (is_dir($fl)) copy_dirs($conn_id, $fl, $flto); else { @copy($fl, $flto); chmod($flto, 0666); } } } } // This function lists a directory function ls_a($wh) { if ($handle = opendir($wh)) { while (false !== ($file = readdir($handle))) { if ($file !== "." && $file !== ".." ) { if(!$files) $files=$file; else $files = $file."\r\n".$files; } } closedir($handle); } $arr=explode("\r\n", $files); return $arr; } $ftp_server = "ftp.server.com"; $conn_id = ftp_connect($ftp_server, "21"); $user = "user"; $passwd = "passwd"; $login_result = ftp_login($conn_id, $user, $passwd); copy_dirs($conn_id, $dir_from, $dir_to); ftp_close($conn_id); ?> ---- Manual Page -- http://www.php.net/manual/en/function.copy.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42379 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42379&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42379&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69590) next »