withought ftp.
from site to my hosting fo开发者_JAVA百科lder. how i can do that?
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)
);
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');
You can use file_get_contents, php is supposed to support network streams; but your folder must be accessible from the outside.
精彩评论