0

我有一个由 PHP 处理的 html 上传表单。以下是上传过程代码:

php上传文件的过程。

if($image["name"] != "")
{
//$path = PATH . DS . "uploads" . DS . "products" . DS . $id;
$path = "../../uploads" . DS . "products" . DS . $id;
if(!is_dir($path))
    {
mkdir($path);
}
chmod($path, 0755);
//move_uploaded_file($image["tmp_name"], $path . DS . $image["name"]);
move_uploaded_file($image["tmp_name"], $path . DS . 
$uploadImage);//exit;               
}

现在我正在尝试使用以下代码同时将此上传的图像传输到另一个网站目录:

另一个网站目录示例:

www.myanotherdomain.fr/onefolder/finalfolder/

转移代码:

// FTP access parameters
$host = 'hostname';
$usr = 'username';
$pwd = 'password';

// file to move:
$local_file = "../../uploads" . DS . "products" . DS . $id;
$ftp_path = "www.myanotherdomain.fr/onefolder/finalfolder";

// connect to FTP server (port 21)
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host");

// send access parameters
ftp_login($conn_id, $usr, $pwd) or die("Cannot login");

// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);

// perform file upload
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII);

// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";

/*
** Chmod the file (just as example)
*/

// If you are using PHP4 then you need to use this code:
// (because the "ftp_chmod" command is just available in PHP5+)
if (!function_exists('ftp_chmod')) {
function ftp_chmod($ftp_stream, $mode, $filename){
    return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename));
}
}

// try to chmod the new file to 666 (writeable)
if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) {
print $ftp_path . " chmoded successfully to 666\n";
} else {
print "could not chmod $file\n";
}

// close the FTP stream
ftp_close($conn_id);

但不幸的是,它没有上传到我的另一个网站目录。我的代码是否有任何错误,或者是否有任何其他方式也可以上传到另一个网站目录。

谢谢。

更新:

Warning: ftp_put() [function.ftp-put]: Prohibited file name:  
www.myanotherdomain.fr/onefolder/finalfolder/ in /home/gastrono1/www/admin/actions
/productAction.php on line 86
Cannot upload 


Warning: ftp_chmod() [function.ftp-chmod]: Could not change perms on 
www.myanotherdomain.fr/onefolder/finalfolder/: No such file or directory in 
/home/gastrono1/www/admin/actions/productAction.php on line 105
4

0 回答 0