简体   繁体   中英

how to upload files from one server to another using move_uploaded_file

I have built a system where my application is running in one server and my database is running in another server. So when I try to upload files, it works fine in the local machine but when I change the location to the other server, it gives the following errors in the error_log file. I have set the ownership of the upload file to apache still it is not working in the remote server.

Following is my php code for file upload...

<?php
$name=$_FILES['file']['name'];
//echo $name;
$size=$_FILES['file']['size'];
$type=$_FILES['file']['type'];
$tmpname=$_FILES['file']['tmp_name'];
echo $tmpname;
$error=$_FILES['file']['error'];
if(isset($name)){
    if(!empty($name)){
        //echo 'ok';
        $location="http://xx.xx.xx.xx/upload/";
        move_uploaded_file($tmpname,$location.$name);
        echo "uploaded";
    }

else 
echo "please choose a file";    
}
?>

and following is the php warning.....

PHP Warning: move_uploaded_file( http://xx.xx.xx.xx/upload/sentence005.TextGrid ): failed to open stream: HTTP wrapper does not support writeable connections in .. PHP Warning: move_uploaded_file(): Unable to move '/tmp/php4kM8Qi' to ' http://xx.xx.xx.xx/upload/sentence005.TextGrid '

Yeah, you cannot use move_uploaded_file() to upload files to a remote location. Use ftp as the other guy mentioned. PHP supports ftp... look into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM