need help in PHP coding to upload directory to frp server
Moderator: General Moderators
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
need help in PHP coding to upload directory to frp server
i need help to upload my directry to ftp server and then i want after uploading remove the directroy from my comuter
i have following program but it is not properly working..
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
form
<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><input name="upload" type="submit" id="upload" /></td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
..................
code
...........
?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";
}
and
function
..................
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
//$ftp_server = "hostname";
//$ftp_user = "username";
//$ftp_pass = "password";
// set up a connection or die
echo"$_user_name";
echo"$_user_pass";
echo" dire === ";
echo"$local_dir";
echo"$remote_dir";
//$_conn_id = ftp_connect($_server) or die("Couldn't connect to $ftp_server");
// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo "Connected as $_user_name@$_server\n";
//$result = true;
//}
// else
// {
//echo "Couldn't connect as $_user_name\n";
//$result = false;
//}
// 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);
$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 . '/');
} 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_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 following program but it is not properly working..
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
form
<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><input name="upload" type="submit" id="upload" /></td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
..................
code
...........
?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";
}
and
function
..................
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
//$ftp_server = "hostname";
//$ftp_user = "username";
//$ftp_pass = "password";
// set up a connection or die
echo"$_user_name";
echo"$_user_pass";
echo" dire === ";
echo"$local_dir";
echo"$remote_dir";
//$_conn_id = ftp_connect($_server) or die("Couldn't connect to $ftp_server");
// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo "Connected as $_user_name@$_server\n";
//$result = true;
//}
// else
// {
//echo "Couldn't connect as $_user_name\n";
//$result = false;
//}
// 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);
$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 . '/');
} 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_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;
}
?>
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: need help in PHP coding to upload directory to frp server
use the code tags to post source code
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
Re: need help in PHP coding to upload directory to frp server
the main problom is, when i puting the name of my local server then it is not reading,code is ok but wwhy it is not accessing my dierectory.
may be i have problom with syntax to define the local directory.
becouse for file in when making its type "type=file" but i dont know what i can make the type for directory in the form. i reciveing the following error
...................
errro
Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 57
Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 58
Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 68
Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 69
Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 86
successfullPHP Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 57 PHP Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 58 PHP Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 68 PHP Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 69 PHP Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 86 .
may be i have problom with syntax to define the local directory.
becouse for file in when making its type "type=file" but i dont know what i can make the type for directory in the form. i reciveing the following error
...................
errro
Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 57
Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 58
Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 68
Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 69
Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 86
successfullPHP Warning: opendir(/c/php) [function.opendir]: failed to open dir: No such file or directory in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 57 PHP Warning: readdir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 58 PHP Warning: closedir(): supplied argument is not a valid Directory resource in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 68 PHP Notice: Undefined variable: f in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 69 PHP Notice: Undefined variable: result in G:\WEBROOT\wilbourn\ftptest\uploadfunctionpage.php on line 86 .
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: need help in PHP coding to upload directory to frp server
What I'm saying is use the code tags provided by the editor in this forum where you are posting your code in order to find a solution to your problem!!!
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
Re: need help in PHP coding to upload directory to frp server
form
<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><input name="upload" type="submit" id="upload" /></td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
..................
code
...........
?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";
}
and
function
..................
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
//$ftp_server = "hostname";
//$ftp_user = "username";
//$ftp_pass = "password";
// set up a connection or die
echo"$_user_name";
echo"$_user_pass";
echo" dire === ";
echo"$local_dir";
echo"$remote_dir";
//$_conn_id = ftp_connect($_server) or die("Couldn't connect to $ftp_server");
// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo "Connected as $_user_name@$_server\n";
//$result = true;
//}
// else
// {
//echo "Couldn't connect as $_user_name\n";
//$result = false;
//}
// 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);
$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 . '/');
} 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_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;
}
?>
<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><input name="upload" type="submit" id="upload" /></td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
..................
code
...........
?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";
}
and
function
..................
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
//$ftp_server = "hostname";
//$ftp_user = "username";
//$ftp_pass = "password";
// set up a connection or die
echo"$_user_name";
echo"$_user_pass";
echo" dire === ";
echo"$local_dir";
echo"$remote_dir";
//$_conn_id = ftp_connect($_server) or die("Couldn't connect to $ftp_server");
// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo "Connected as $_user_name@$_server\n";
//$result = true;
//}
// else
// {
//echo "Couldn't connect as $_user_name\n";
//$result = false;
//}
// 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);
$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 . '/');
} 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_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;
}
?>
Code: Select all
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
Re: need help in PHP coding to upload directory to frp server
Code: Select all
<?php
//Move or Upload Folder Using PHP FTP Functions
function moveFolder($_server, $_user_name, $_user_pass, $local_dir, $remote_dir) {
//$ftp_server = "hostname";
//$ftp_user = "username";
//$ftp_pass = "password";
// set up a connection or die
echo"$_user_name";
echo"$_user_pass";
echo" dire === ";
echo"$local_dir";
echo"$remote_dir";
//$_conn_id = ftp_connect($_server) or die("Couldn't connect to $ftp_server");
// try to login
//if (ftp_login($conn_id, $_user_name, $_user_pass)) {
//echo "Connected as $_user_name@$_server\n";
//$result = true;
//}
// else
// {
//echo "Couldn't connect as $_user_name\n";
//$result = false;
//}
// 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);
$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 . '/');
} 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_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;
}
?>
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
Re: need help in PHP coding to upload directory to frp server
this code is for that page who catch values from 'form'
and assing it to fuctiontion
and assing it to fuctiontion
Code: Select all
<?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";
}
?>
-
asifkamalzahid
- Forum Commoner
- Posts: 36
- Joined: Tue Nov 18, 2008 8:00 am
Re: need help in PHP coding to upload directory to frp server
form code
Code: Select all
<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><input name="upload" type="submit" id="upload" /></td>
<td> </td>
</tr>
</table>
<p> <