0

I want to move an image from the folder www.abc.com/upload/abc.jpg to www.def.com/upload/abc.jpg. Here these two website have same cpanel of godaddy but their ftp details are different.. how can I move that image ?

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

 ?>

it is not working . But it will work when i am using ftp_put() function, this function needs ftp username and password.. i want to move the image without ftp details. how can i move it and is it possible?

Ranjith
  • 2,779
  • 3
  • 22
  • 41
Suresh Kamal
  • 9
  • 2
  • 6
  • You mentioned everything except the most important thing - are the two websites on the same physical server or not? If yes, then the answer is trivial. If not, then you mount the TARGET server's upload directory so the SOURCE one can see it. After that it's just copying one file to a directory. – N.B. Apr 24 '13 at 10:00

1 Answers1

1

Try this solution:

# 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);

Add this file in your another domain..

# 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";
}
Pankaj Dadure
  • 679
  • 5
  • 11