1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

copy file from weblink how

Discussion in 'PHP' started by arctushar, Oct 29, 2009.

  1. #1
    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
     
    arctushar, Oct 29, 2009 IP
  2. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What type of server do you have and is it only restricted to a PHP script?
     
    CodedCaffeine, Oct 29, 2009 IP
  3. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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:
     
    CodedCaffeine, Oct 29, 2009 IP
  4. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #4
    
    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.
     
    AsHinE, Oct 29, 2009 IP
  5. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    use simple copy() function...
     
    xenon2010, Oct 30, 2009 IP
  6. CodedCaffeine

    CodedCaffeine Peon

    Messages:
    130
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    CodedCaffeine, Oct 30, 2009 IP
  7. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #7
    Actually this possibility (copy files from remote servers) depends from your server config, AFAIK.
     
    AsHinE, Oct 31, 2009 IP
  8. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I used copy() function only with images..
    just to grab images and articles from football news sites..
     
    xenon2010, Oct 31, 2009 IP