hello everybody I need to copy file from weblink to my site. how its possible. for example ther is a file name http://otherweb.com/abc.exe now I want to copy abc.exe to myweb.com. how can I do that. In simple way direct copy file without download+upload
Anyway, here is a PHP script that allows you to save files from another web server onto your own. <?php /************************ * cURL File Downloader ************************* * Written by Joel Larson (Coded Caffeine) * * Description: Downloads a file based on a URL and saves on * a web server. ************************/ /************************ * EDIT VARIABLES! ************************/ #The URL of the file to download. $url = 'http://samplewebsite.com/download_file.exe'; #The name of the file you want saved on your server. #NOTE: This will save in the directory with the PHP script! $filename = 'downloaded_file.exe'; /************************ * SCRIPT SCRIPT SCRIPT! ************************/ #Initiate the curl handle. $ch = curl_init(); #Set the file url we're getting. curl_setopt($ch, CURLOPT_URL, $url); #Create a file for cURL to write in. $fp = fopen($filename, 'w'); #Write to the file with cURL. curl_setopt($ch, CURLOPT_FILE, $fp); #Execute the above commands. curl_exec($ch); #Close the open handles. curl_close($ch); fclose($fp); PHP:
copy('http://otherweb.com/abc.exe','/yourhost_path/filename.exe'); PHP: One detail - your second param usually should be your file path, not your file url. Read for details in php copy function manual.
Wow! I didn't realize that copy() could be used for a file not located on your computer. I guess one learns something every day.. haha.
I used copy() function only with images.. just to grab images and articles from football news sites..