<?php
// This is the directory we want to create
$dir = "newdir";
// This is the URL on the remote server of the
// script that is going to FTP back to us.
$url = "http://ftpenabled.server.com/ftp.php?dir=$dir";
// This just checks if the directory already exists ....
// if it doesn't call our remote script to FTP back to
// us and create it.
// Also check "allow_url_fopen" is enabled.
if(!file_exists("/var/www/html/testdomain/public_html/$dir"))
{
// Now open the URL. The remote script can pass data back to
// us in $var
$fh = fopen($url,"r");
while(!feof($fh))
{
// Just to stop it timing out ... FTP isn't fast!
set_time_limit(10);
$var = fgets($fh, 1024);
print($var);
}
fclose($fh);
}
}
?>
This is the remote file http://ftpenabled.server.com/ftp.php
<?php
// If the server where this file is located
// has the FTP portion of PHP enabled then
// you call just run this function locally.
// Dir is the directory to create
$dir = $HTTP_GET_VARS["dir"];
// These 3 variable you could pass to the
// script within the URL if you wanted -
// bit insecure though
$ftp_ip = "ftp.this.com";
$ftp_username = "username";
$ftp_password = "password";
if($ftp=ftp_connect($ftp_ip))
{
if(ftp_login($ftp,$ftp_username,$ftp_password))
{
// Set to PASV mode
ftp_pasv( $ftp, 1);
// In this example set the current directory to
// public_html
ftp_chdir($ftp,"/public_html/");
// If we cannot set our directory to the new one
// then we create it
if(!ftp_chdir($ftp,$dir))
{
ftp_mkdir($ftp,$dir);
echo("Directory $dir created ok");
}
}
ftp_close($ftp);
}
?>Скопировать в буфер
© Copyright 2008-2012 by KDG