Jump to content

file directories, and directory access/structure


Ninjakreborn

Recommended Posts

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
Share on other sites

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 Function

ftp_dwn($fromDir = "cwillard/sites/BioPharm/website/",$toDir = "custom",$chmod = 0755,$detail = 1);
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.