2

How can I return to the ftp users root folder. In this example it is /isi/ in my home/user/ dir.

        $location = $order;
        $real_location = $workflow_location =$leverancier;

        if (!@ftp_chdir($ftp_conn, $real_location)) {
            ftp_mkdir($ftp_conn, $real_location);
        }

        foreach($maps as $map) {
            $real_location = $real_location . '/' . $map;
            $workflow_location = $workflow_location . '~' . $map;

            if (!@ftp_chdir($ftp_conn, $real_location)) {
                ftp_mkdir($ftp_conn, $real_location);
                ftp_chdir($ftp_conn, $real_location);
            }

        }
        // ISI is the root folder
        if (ftp_chdir($ftp_conn, '/isi/')) { 
          echo "ftp_chdir successful\n";
        } else {
          echo "ftp_chdir not successful\n";
        }
        exit;

---------------------------------------------------------- EDIT ----------------------------------------------------------------

Not realy a clean way to do it, but putting this after the code is poster above did the trick. I counted the folders, this way I did know how many times I've to use the ftp_cdup function.

   $i = count($maps);
        $i++;
        while($i > 0) {
            ftp_cdup($ftp_conn);
            $i--;
        }

---------------------------------------------------------- EDIT2 ---------------------------------------------------------------

Other solution:

ftp_chdir($ftp_conn, '~');
Dyam
  • 33
  • 5
  • You mean, `users HOME folder`? On Linux machines `~` simbolizes users home directory, so... `ftp_chdir($ftp_conn, '~');` should do the thing. – Kamiccolo Mar 07 '14 at 15:32
  • That did the trick also, I think your solution is much better. Thanks for sharing! – Dyam Mar 07 '14 at 15:36

1 Answers1

2

On Linux machines You can address current user's home directory as ~.

So, one of the possible solutions would be just using ftp_chdir($ftp_conn, '~');.

More on this topic:

Kamiccolo
  • 5,791
  • 3
  • 35
  • 42