[SOLVED]upload file then send it to another over FTP
Posted: Tue Sep 05, 2006 2:46 am
Hi everyone, I have done some search&browse on forum but didn't find what I'm looking for.
I have 2 files, 1 is foe handling uploaded file(move_uploaded_file()) and in second is function wich should uploaded file transfer to other FTP location so I will have files on both servers, here is the code:
and file with ftp function is here:
Upload works fine, I have a problem with FTP
Any help is appreciated
Regards
I have 2 files, 1 is foe handling uploaded file(move_uploaded_file()) and in second is function wich should uploaded file transfer to other FTP location so I will have files on both servers, here is the code:
Code: Select all
<?
//
// Edit product form
//
session_start();
require_once("../conn.php");
require_once("../template.inc.php");
//ZV include file to upload on other server
include_once "add-file.php";
$DOWNLOAD_SERVER = '';
set_time_limit(0);
$row_ccid = @mysql_fetch_array(@mysql_query("select * from links WHERE id = $id"));
if (!$productid)
$productid = $row_ccid['productid'];
if($action=='edit')
{
// Upload product
$file2 = $row_ccid['plink'];
if($plink!="" && file_exists ($plink))
{
@unlink($row_ccid["plink"]);
$file2 = realpath('../products') . "/" . $HTTP_POST_FILES['plink']['name'];
if (move_uploaded_file($plink, $file2))
{
//call ftp upload
ftp_upload($plink, $file2);
chmod($file2,0644);
$pplink = $DOWNLOAD_SERVER . str_replace("/home/rrs/public_html","",$file2);
}
else
$file2 = "";
}
elseif ($pplink)
{
if (!preg_match("/^(ht|f)tp[s]?:\/\//i",$pplink) && !$row_ccid['plink'])
$pplink = "http://$pplink";
}
else
$pplink = $row_ccid['pplink'];
if ($id)
mysql_query("update links set
name = '$name',
plink = '$file2',
pplink = '$pplink'
WHERE id = $id");
else
mysql_query("insert into links (
productid,
name,
plink,
pplink
) values (
'$productid',
'$name',
'$file2',
'$pplink'
)");
?>
<script language='Javascript'>
if (window.opener)
window.opener.location.reload(window.opener.location.href);
window.close();
</script>
<body onload='window.close()'>
</body>
<?
exit;
}
$t = new Smarty_RRS;
$t->assign("pid",$productid);
$t->assign("id",$id);
$t->assign("row_ccid",$row_ccid);
$t->assign("max_filesize",ini_get("upload_max_filesize"));
$t->display('madmin/edit_linknew.tpl');
?>Code: Select all
<?php
define("FTP_HOST","xxx.xxx.xxx.xxx");
define("FTP_USERNAME","xxxxx");
define("FTP_PASSWORD","xxxxx");
define("FTP_FILE_PATH","../../var/www/html/products/");
function ftp_upload($ftp_source_file, $filename)
{
$remote_file = FTP_FILE_PATH.$filename;
//setup basic connection
$connection_id = ftp_connect(FTP_HOST);
//connect with username and password
$ftp_login = ftp_login($connection_id,FTP_USERNAME,FTP_PASSWORD);
//check for connection
if((!$connection_id) || (!$ftp_login))
{
echo "FTP connection has failed!";
exit;
}
//upload file
$ftp_upload = ftp_put($connection_id, $remote_file, $ftp_source_file, FTP_ASCII);
//check for upload file
if (!$ftp_upload)
{
echo "FTP upload has failed!";
exit;
}
//close connection
ftp_close($connection_id);
return true;
}//ftp_upload($ftp_source_file, $filename)
?>Any help is appreciated
Regards