phpserverfile-transferhosted

How to copy file from hosted server to local drive using PHP


I am trying to transfer a file between my hosted server and my local computer.

I have managed to make it work from my local computer to my hosted server, but not in the other direction.

The error I get is:

Failed to open stream : No such file or directory

Here is my code:

if(isset($_POST['btnSend'])) //submit button
{   
      if(count($_FILES['upload']['name']) > 0)

      //Loop through each file
        for($i=0; $i<count($_FILES['upload']['name']); $i++) {

            //Get the temp file path
            $tmpFilePath = $_FILES['upload']['tmp_name'][$i];
            $fileType=$_FILES['upload']['type'][$i];

            //Make sure we have a filepath
            if($tmpFilePath != ""){

                //save the filename
                $shortname = $_FILES['upload']['name'][$i];

                $fp      = fopen($tmpFilePath, 'r');
                $content = fread($fp, filesize($tmpFilePath));
                fclose($fp);
                $content = addslashes($content);    

                $path  = 'D:/Resumes_processed/'.$shortname;

                copy($tmpFilePath, $path);
            }
       }
}

Solution

  • You need to use an FTP client from your local computer to access the server. The server itself cannot write to your local computer, unless you turn it into a server itself.