2013-05-13 27 views
7

Diciamo che c'è un file su un server remoto che può essere scaricato senza restrizioni, es. puoi mettere il link diretto al file nel tuo browser e scarica il file, ad esempio http://www.remotesite.com/video.avi chiederà al tuo browser di scaricare quel file. Usando php, qual è il modo migliore per prendere quel file e caricarlo sul mio server locale senza che il file venga scaricato sul mio PC, cosa succede a phpBB se metti un url nel modulo di caricamento del file? Sarebbe anche apprezzato un esempio del codice necessario. GrazieIl modo migliore per ottenere un file dal server remoto e copiare sul server locale utilizzando php

+0

http://php.net/manual/en/function.file- get-contents.php –

risposta

23

Basta usare copy

$source = "http://www.remotesite.com/video.avi"; 
$dest = "video.avi"; 
copy($source, $dest); 
+1

sembra interessante di 'file_get' e' file_put' :) –

+1

Semplicità hashtag –

3
$remote_file_contents = file_get_contents('http://remote_url/file/with.extension'); 
//Get the contents 

$local_file_path = 'your/local/path/to/the/file/with.extension'; 

file_put_contents($local_file_path, $remote_file_contents); 
//save the contents of the remote file 
+0

http://www.php.net/manual/en/function.file-put-contents.php –

2

È possibile leggere e scrivere il file senza browser scaricare

<?php 

$file = 'http://www.remotesite.com/video.avi'; 

// read the file from remote location 
$current = file_get_contents($file); 

// create new file name 
$name = "path/to/folder/newname.avi"; 

// Write the contents back to the file 
file_put_contents($file, $current); 
Problemi correlati