PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 12, 2019 10:31 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Aug 28, 2010 10:36 am 
Offline
Forum Commoner

Joined: Wed Mar 15, 2006 7:39 pm
Posts: 35
This is a function I wrote to create directories that do not exist before I perform a ftp_put. Is this already built into PHP or is there a better way of going about this? Thanks!

Syntax: [ Download ] [ Hide ]
//example usage...
$file = "temp123/temp456/temp789/myfile.txt";
checkforAndMakeDirs($ftp_con, $file);
ftp_put($ftp_con, $file);

function checkForAndMakeDirs($connection, $file) {
        $origin = ftp_pwd($connection);
        $parts = explode("/", dirname($file);

        foreach ($parts as $curDir) {
            // Attempt to change directory, suppress errors
            if (@ftp_chdir($connection, $curDir) === false) {
                ftp_mkdir($connection, $curDir); //directory doesn't exist - so make it
                ftp_chdir($connection, $curDir); //go into the new directory
            }
        }

        //go back to the origin directory
        ftp_chdir($connection, $origin);
}
 


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group