Upload to host

Discussion in 'PHP' started by xor83, Feb 5, 2008.

  1. #1
    I want to upload file to my dreamhost server from other URL location is that possible?. There are many upload sample which upload files from clients local machine but i want to upload from different location can i do that? any help?
     
    xor83, Feb 5, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    $source = 'http://source.com/file.xxx';
    $target = 'path/to/folder/file.xxx';
    
    echo @copy($source, $target)
        ? 'File saved'
        : 'Error receiving file';
    
    PHP:
    This is probably the easiest way. (Not the safest though)
     
    nico_swd, Feb 6, 2008 IP
  3. xor83

    xor83 Well-Known Member

    Messages:
    181
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    thax for help
    this is not working. I just want to save my bandwidth i want that dreamhost use their bandwidth to download files from URL location(internet not local files).
     
    xor83, Feb 6, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Remove the @ and tell me what error you get.
     
    nico_swd, Feb 6, 2008 IP
  5. xor83

    xor83 Well-Known Member

    Messages:
    181
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    Error i am getting

    Note: I am successfully connect to my ftp account

    this code works fine
    $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

    but it uses my bandwidth
     
    xor83, Feb 6, 2008 IP
  6. NeverTheSame

    NeverTheSame Peon

    Messages:
    94
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Use RapidLeech. It's a PHP script. Try searching on Google.
     
    NeverTheSame, Feb 6, 2008 IP
  7. WebHostingNerds.com

    WebHostingNerds.com Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    doesn't dreamhost come with SSH access?
    just navigate to the directory you want to download the file to
    use 'cd directoryname' to go into a directory and 'cd ..' to come back to the upper level
    when you're in the directory you decided to download the file to type 'wget http :// www. domain. com/path/to/the/file' (with no spaces) and the server will download a copy of the file to the current directory

    you can use a client like putty (google for it) to access the server via SSH
     
    WebHostingNerds.com, Feb 6, 2008 IP
  8. bond1

    bond1 Active Member

    Messages:
    248
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #8
    it will use the bandwidth
     
    bond1, Feb 6, 2008 IP
  9. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #9
    I'm pretty sure, though not positive, that any script you make or use will take up your given bandwidth- the only things that do not are the control panel your host includes, and your root ftp. (Heh, correct me if I'm wrong though. . .) Basically anything over port 80 [HTTP] they will monitor and update your remaining bandwidth.
     
    ToddMicheau, Feb 6, 2008 IP
  10. paradoxist1

    paradoxist1 Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    you'll need to use curl

    look at php.net/curl for documentation. If you cannot find it, i'll put some code sample here. But you need to specify the transfer, the connection type, headers, etc and you'll be easily able to transfer files.
     
    paradoxist1, Feb 6, 2008 IP
  11. paradoxist1

    paradoxist1 Peon

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Here's my actual code:
    function getcontents($filename)
    {
        if ($file = @file_get_contents($filename))
        {
        }
        else
        {
            $curl = curl_init($filename);
            curl_setopt($curl, CURLOPT_HEADER, 0); // ignore any headers
            ob_start(); // use output buffering so the contents don't get sent directly to the browser
            curl_exec($curl); // get the file
            curl_close($curl);
            $file = ob_get_contents(); // save the contents of the file into $file
            ob_end_clean(); // turn output buffering back off
        }
        return $file;
    }
    
    Code (markup):
     
    paradoxist1, Feb 6, 2008 IP
  12. xor83

    xor83 Well-Known Member

    Messages:
    181
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #12
    thx paradoxist1 for the info

    i can't use Control panel to upload files bcuz i want to upload about 50k files so need to write some code where i can run loops to finish this job
     
    xor83, Feb 8, 2008 IP