Ninjakreborn Posted October 16, 2006 Share Posted October 16, 2006 Can someone tell me some stuff about directories, directory structures, and accessing files within a directory.Or show me a good tutorial on it, I looked everywhere for something pretty good.I need to know stuff like how to access them.When to put ./, when to put / or ../ I had someone help me with it some, but I don't really understand.I know a little, but that's one of my weak spots, any advice? Link to comment https://forums.phpfreaks.com/topic/24104-file-directories-and-directory-accessstructure/ Share on other sites More sharing options...
makeshift_theory Posted October 16, 2006 Share Posted October 16, 2006 Well I had the same dilema, I was trying to ftp a local site structure to a remote location and after a week of testing I finally got it to work, below is the script. It goes through each directory in the local side and uploads the files to a remote destination.By the way I "x'ed" out all of the ftp variables so don't actually use test.com haha[code]<?/* FTP Upload Script Variable Definition: $detail if turned on (with any variable passed to it) will display all error messages and system messages Psuedocode: Grab All Files from local Create First Folder Name Change Directory to Created Check if File or Folder -> If File Upload to Directory -> If Folder Create Folders and cycle back through process with this name as the "FROM" ### Written By: Christopher Willard ### ########### Date: 10/16/06 ############ */function ftp_dwn($fromDir,$toDir,$chmod,$detail) {// Initialize FTP Server$ftp_server = "ftp.test.com";$ftp_user_name = "########";$ftp_user_pass = "#@#@#@#@#@#@#@";$conn_id = ftp_connect($ftp_server);$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);if((!$conn_id) || (!$login_result)) $error[] = "Could not Connect to the FTP Server"; ftp_mkdir($conn_id, $toDir); ftp_site($conn_id, 'CHMOD 0777 '.$toDir); ftp_chdir($conn_id,$toDir); // First run this will be custom///echo ftp_pwd($conn_id); // Test to see the current ftp directory;// Initialize Exception Array$exceptions = array('.','..'); if ($handle = opendir($fromDir)) { while (false !== ($file = readdir($handle))) if (!in_array($file,$exceptions)) { // handle slash exceptions $from=str_replace('//','/',$fromDir.'/'.$file); if (is_file($from)) { // If local file is a file handle here //echo $toDir . "/" . $file . "<br><br>"; if(!ftp_put($conn_id,$file,$from,FTP_ASCII)) $error[] = "Could not upload " . $toDir . "/" . $file . " correctly<br><br>"; if(!ftp_site($conn_id,$chmod,$toDir . "/" . $file)) $error[] = "Could not chmod " . $toDir . "/" . $file . " successfully.<br><br>"; } if(is_dir($from)) { // If local file is a folder handle here ftp_dwn($from,$toDir . "/" . $file,$chmod,$detail=1); // $toDir = custom/css } } // End Exception IF closedir($handle); } else $error[] = "Cannot Find Source Folder!"; // End Directory Handling if($detail) { // If Error Detail Is Turned On foreach ($error as $err) echo "<font color=red><b>" . $err . "</b></font>"; if(!$error) echo "<font color=navy><b>FTP Structure Uploaded Successfully.</b></font>";}} // End Functionftp_dwn($fromDir = "cwillard/sites/BioPharm/website/",$toDir = "custom",$chmod = 0755,$detail = 1);?>[/code] Link to comment https://forums.phpfreaks.com/topic/24104-file-directories-and-directory-accessstructure/#findComment-109564 Share on other sites More sharing options...
Ninjakreborn Posted October 16, 2006 Author Share Posted October 16, 2006 actually that will help a lot, I appreciate it.Thanks again. Link to comment https://forums.phpfreaks.com/topic/24104-file-directories-and-directory-accessstructure/#findComment-109590 Share on other sites More sharing options...
makeshift_theory Posted October 16, 2006 Share Posted October 16, 2006 No problem. I fought for a week with that script so I definately don't mind passing it on to save others the headache. Link to comment https://forums.phpfreaks.com/topic/24104-file-directories-and-directory-accessstructure/#findComment-109602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.