Jump to content


This topic is now archived and is closed to further replies.


file directories, and directory access/structure

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?

Share this post

Link to post
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

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

  if (is_file($from))
  { // If local file is a file handle here
    //echo $toDir . "/" . $file . "<br><br>";
  $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 local file is a folder handle here
  ftp_dwn($from,$toDir . "/" . $file,$chmod,$detail=1); // $toDir = custom/css

  } // End Exception IF

} 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>";

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);

Share this post

Link to post
Share on other sites


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.