this is for code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="upload.php">
Move or Upload Folder Using PHP FTP Functions<br />
</p>
<table width="373" border="1">
<tr>
<td width="184">server address </td>
<td width="173"><input type="text" id="server_name" name="server_name" /></td>
</tr>
<tr>
<td>user name </td>
<td><input type="text" name="user_name" id="user_name" /></td>
</tr>
<tr>
<td>user password</td>
<td><input type="text" id="user_password" name="user_password" /></td>
</tr>
<tr>
<td>local directory</td>
<td><input type="text" name="local_dir" id="local_dir" /></td>
</tr>
<tr>
<td>remote directory</td>
<td><input type="text" name="remote_dir" id="remote_dir" /></td>
</tr>
<tr>
<td> </td>
<td><input name="upload" type="submit" id="upload" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
this is the upolad page
<?php
// Start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
$_server = $_POST["server_name"];
$_user_name = $_POST["user_name"];
$_user_pass = $_POST["user_password"];
$local_dir = $_POST["local_dir"];
$remote_dir = $_POST["remote_dir"];
require ("uploadfunctionpage.php");
$uploadfunction = moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir);
if($uploadfunction=true)
{
echo " successfull";
}
else
{
echo "failed";
}
?>
this is the fuction whis making connection with ftp and upolading files
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
echo"$_user_name <br/>";
echo"$_user_pass <br/>";
echo" directories are : <br/>";
echo"$local_dir<br/>";
echo"$remote_dir <br/>";
$file = $remote_dir;
// set up basic connection
$_conn_id = ftp_connect($_server);
// login with username and password
$_login_result = ftp_login($_conn_id, $_user_name, $_user_pass);
// check connection
if ((!$_conn_id) || (!$_login_result)) {
$_error = "FTP connection has failed!";
$_error .= "Attempted to connect to $_server for user $_user_name";
$result = false;
} else {
$_error = "Connected to $_server, for user $_user_name";
}
$conn_id = $_conn_id;
@ftp_mkdir($conn_id, $remote_dir);
echo "successfully created $remote_dir\n";
$handle = opendir($local_dir);
while (($file = readdir($handle)) !== false) {
if (($file != '.') && ($file != '..')) {
if (is_dir($local_dir . $file)) {
//recursive call
moveFolder($conn_id, $local_dir . $file . '/', $remote_dir . $file . '/');
echo "successfully uploaded $file\n";
} else
$f[] = $file;
}
}
closedir($handle);
if (count($f)) {
sort($f);
@ftp_chdir($conn_id, $remote_dir);
foreach ($f as $files) {
$from = @fopen("$local_dir$files", 'r+');
$moveFolder = ftp_fput($conn_id, $files, $from, FTP_ASCII);
// @ftp_fput($conn_id, $files, $from, FTP_BINARY);
// check upload status
if (!$moveFolder) {
$this->_error = "FTP upload has failed! From:" . $local_dir . " To: " . $remote_dir;
$result = false;
} else {
$this->_error = "Uploaded $local_dir to $remote_dir as $this->_server";
$result = true;
}
}
}
return $result;
}
?>
i have this error message
Warning: opendir(/c) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 34
Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 35
Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 48
Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 49
Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 66
successfullPHP Warning: opendir(/c) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 34 PHP Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 35 PHP Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 48 PHP Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 49 PHP Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 66