将文件上传到另一个域Codeigniter

时间:2017-04-22 18:07:35

标签: php codeigniter cpanel

我有“www.mine.com/one”和“www.mine.com/two”。 我想将文件从“www.mine.com/two”上传到“www.mine.com/one”中的“images”文件夹。我不知道如何实现它。我是否需要将文件夹权限更改为777? 我尝试使用ftp协议上传现有文件(img_1.jpg)。

$remote_file = 'http://mine.com/one/images/';
$ftp_host = 'localhost'; 
$ftp_user_name = 'mine'; 
$ftp_user_pass = 'mine123'; 
$local_file = 'http://mine.com/two/uploads/img_1.jpg';                               
$connect_it = ftp_connect( $ftp_host );

if(ftp_login( $connect_it, $ftp_user_name, $ftp_user_pass )){
   if ( ftp_put($remote_file, $local_file, FTP_BINARY ) ) {
      redirect('SUCCESS');
  }
  else {
     redirect('FAIL');
  }
}

结果总是重定向到'FAIL'。你可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

嗯,好像,你正在连接你的" localhost"然后尝试将文件上传到http://mine.com/one/images/,这两行不能一起使用:

$remote_file = 'http://mine.com/one/images/';
$ftp_host = 'localhost';

它需要更像远程文件相对于您的ftp根文件夹并且缺少文件名

$remote_file = '/one/images/img_1.jpg';

此外,您错过了ftp_put的第一个需要资源的参数:

  if ( ftp_put($remote_file, $local_file, FTP_BINARY ) ) {

应该是

 if ( ftp_put($connect_it, $remote_file, $local_file, FTP_BINARY ) ) {

希望这有帮助, 请在此处查看许多示例和文档:

http://php.net/manual/en/ref.ftp.php

在你的情况下看到这些:

http://php.net/manual/en/function.ftp-put.phphttp://php.net/manual/en/function.ftp-connect.php

相关问题