tags:

views:

28

answers:

3

withought ftp.

from site to my hosting folder. how i can do that?

+1  A: 

You can download from a foreign server and write to the filesystem (if you have permissions for the current directory, otherwise you could write to /tmp or wherever you have permissions).

$file = 'test.jpg';
file_put_contents($file, 
    file_get_contents("http://example.com/" . $file)
 );
Andy
A: 

You can use file_get_contents, php is supposed to support network streams; but your folder must be accessible from the outside.

Aif
+1  A: 

You can also use cURL for this, which might be useful if the PHP setting allow_url_fopen is not enabled:

<?php

function fetch_url($url, $output_file) {
    $stream = fopen($output_file, 'w');
    if ($stream === false) {
        throw new Exception('Cannot write to file');
    }

    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_FILE, $stream);
    $result = curl_exec($curl);

    curl_close($curl);
    fclose($stream);

    if ($result === false) {
        throw new Exception('cURL Error: ' . curl_error($curl));
    }
}

fetch_url('http://www.example.com', '/some/file');
Tom Haigh