我有一个html上传表单,由Php处理。以下是上传流程代码:
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