0

我想将图像从文件夹移动www.abc.com/upload/abc.jpgwww.def.com/upload/abc.jpg. 这两个网站有相同的godaddy cpanel,但它们的ftp 细节不同.. 我怎样才能移动那个图像?

  <?php
   move_uploaded_file($_FILES["file"]["tmp_name"],
  "C:\inetpub\vhosts\def.com\upload\\" . $_FILES["file"]["name"]);

 ?>

它不工作。但是当我使用ftp_put()函数时它会起作用,这个函数需要 ftp 用户名和密码。我想在没有 ftp 详细信息的情况下移动图像。我怎样才能移动它,有可能吗?

4

1 回答 1

1

试试这个解决方案:

# Source domain code..
$save_dir = 'C:\inetpub\vhosts\abc.com\upload\abc.jpg' ;# Temporary save file in your source domain..
$url = "http://www.def.com/copy_upload_file.php"; # destination domain URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
    "file"=> "@".$save_dir,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);

将此文件添加到您的另一个域中..

# Destination domain file called as copy_upload_file.php
$path = 'C:\inetpub\vhosts\def.com\upload\'; # Write full path here
if(isset($_FILES["file"]))
{
    if ($_FILES["file"]["error"] > 0)
    {
        echo "0";
    }
    else
    {
        if(is_uploaded_file($_FILES["file"]["tmp_name"]) && move_uploaded_file($_FILES["file"]["tmp_name"], $path . $_FILES["file"]["name"]))
        {
            echo "1";
        }
        else {
            echo "0";
        }
    }
}
else
{
    echo "0";
}
于 2013-04-24T10:21:45.433 回答