Php download script

Discussion in 'PHP' started by gica.gica56, Sep 5, 2010.

  1. #1
    Hi everybody. I'm new here and a beginner on PHP scripting. I'm trying to write a php code

    in order to do this:
    1. start downloading a file from an HTTP server (an address like this:

    http://free.com/get/0dw0bs/my_movie.flv). The file has about 500 Mb. The file is not on my

    website host, it's on a different host.
    2. the file to be downloaded on my webserver on my folder named "videos" with a name like

    this: my_movie_id.flv where id is a number that is incremented everytime the page is

    accesed (this will be stored in mySQL database).
    3. during download I want to be able to use my_movie_id.flv for streaming and if the page

    is changed or the browser is closed I want this file to be deleted from my webserver.

    I've tried and studied php codes for 2 weeks now and I haven't been able to make it work.

    I've write some php script but none of them downloaded all of the movie (only 10kb or

    something like that).
    If anyone can help or give me some ideas how can this be done I'll really appreciate it.

    Thanks a lot for your time to read this.
     
    gica.gica56, Sep 5, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    I'm not sure what methods you've used to download this file, but this cannot be done with file_get_contents( ) function because you are trying to download a huge amount of file. Your only option is cURL, but you will have to consider your webhost's limitation and the way your server is setup/ ;)
     
    Rainulf, Sep 5, 2010 IP
  3. gica.gica56

    gica.gica56 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the advice.

    This is my script:

    <html>
    <form method="post">
    <input name="url" size="50" value="http://glb-b3.dl4free.com/get/0dw0bs/The_Others.flv" />
    <input name="submit" type="submit" />
    </form>
    <?php





    // maximum execution time in seconds
    set_time_limit (24 * 60 * 60);

    if (!isset($_POST['submit'])) die();

    // folder to save downloaded files to. must end with slash
    $destination_folder = 'videos/';

    $url = $_POST['url'];
    $newfname = $destination_folder . basename($url);

    $file = fopen ($url, "rb");
    if ($file) {
    $newf = fopen ($newfname, "wb");

    if ($newf)
    while(!feof($file)) {
    fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
    }
    }

    if ($file) {
    fclose($file);
    }

    if ($newf) {
    fclose($newf);
    }

    ?>

    </html>

    It must be wrong somewhere but I couldn't figure it out yet.
     
    gica.gica56, Sep 9, 2010 IP