简体   繁体   中英

How to move a php file from server to server

I am doing a Wordpress plugin that once you activate the plugin I want to copy some templates from a external repo(server) to the downloads folder in the current wordpress instance.

What I have done so far is this which works fine but the problem is that is trying to execute the php code functions inside, I am getting this erro fomr the error log :

[26-Sep-2014 00:11:47 America/Chicago] PHP Fatal error: Call to undefined function get_the_title() in /home/german/public_html/wp-content/uploads/template/squeeze-land.php on line 21

So is trying to execute the get_the_titel() function

I'd like to move a file to a target folder in another server. thank you.

function getTemplates(){

       $url = 'http://domain.com/wp-content/uploads/template/squeeze-land.php';
       $newFile = $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/template/testing.php';

        set_time_limit(0); //Unlimited max execution time

        $path = $newFile;
        $url = $url;
        $newfname = $path;
        echo 'Starting Download!<br>';
        $file = fopen ($url, "rb");
        if($file) {
            $newf = fopen ($newfname, "wb");
            if($newf)
                while(!feof($file)) {
                    fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
                    echo '1 MB File Chunk Written!<br>';
                }
        }
        if($file) {
            fclose($file);
        }
        if($newf) {
            fclose($newf);
        }
        echo 'Finished!';
}

Why don't you use "CURL" to copy the templates from other server to your server... This will help you more...

Hope so this link will help you as well..

How to send file data via curl to another server in $_FILES

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