Icy Phoenix

     
 



Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post PHP Files Downloader (Needs A Files Sequence Or List) 
 
Today I would like to share with you a small script I coded yesterday because I found a good resources site to download from.

I noticed that all files where named sequentially: 'file_001.zip', 'file_002.zip', ... 'file_xxx.zip'

Instead of downloading files one by one by manually clicking and load pages, I decided to go using PHP.

Here are the instructions and the code:
  • First make sure you have a local server on your pc or a remote server with PHP running.
  • Suppose you need to download a lof of files which are named sequentially from website: 'file_001.zip', 'file_002.zip', ... 'file_xxx.zip'.
  • Create on your local (or remote) server a folder called "downloader" (or any name you like) and put this file in that folder:
    Code: (downloader.php) [Download] [Hide] [Select]
    <?php
    /**
    *
    * @package Icy Phoenix
    * @version $Id$
    * @copyright (c) 2008 Icy Phoenix
    * @license http://opensource.org/licenses/GPL-license.php GNU Public License
    *
    */

    @set_time_limit(0);
    //@ignore_user_abort(true);
    @ini_set('memory_limit', '64M');

    page_header('Files Downloader');

    $folder_src = 'http://www.targetsite.com/';
    $folder_tgt = 'files/';

    $filename_base_src = 'file_';
    $filename_base_tgt = 'file_';


    $files_src = array();
    $files_tgt = array();

    echo('<br /><br /><br /><h1>Files</h1>');
    flush();
    echo('<ul>');

    for ($i = 1; $i < 1000; $i++)
    {
        
    $filename_suffix = str_pad($i, 3, '0', STR_PAD_LEFT);
        $filename_src = $filename_base_src . $filename_suffix . '.zip';
        $filename_tgt = $filename_base_tgt . $filename_suffix . '.zip';

        $filename_full_path_src = $folder_src . $filename_src;
        $filename_full_path_tgt = $folder_tgt . $filename_tgt;

        //if (@remote_file_exists($folder_src, $filename_src) && @!file_exists($filename_full_path_tgt))
        if (@!file_exists($filename_full_path_tgt))
        {
            $files_src[] = $filename_full_path_src;
            $files_tgt[] = $filename_full_path_tgt;
            $copy_result = @copy($filename_full_path_src, $filename_full_path_tgt);
            echo('<li style="font-size: 9px;">Copying: <b>' . $filename_tgt . '</b> ยป ' . (!empty($copy_result) ? '<span style="color: #228822;">OK</span>' : '<span style="color: #dd2200;">ERROR</span>') . '</li>');
            flush();
        }

    }

    echo('</ul>');

    echo('<br /><br /><br /><b>Work Complete!!!</b>');
    page_footer();
    exit;

    function page_header($page_title)
    {
        $encoding_charset = 'UTF-8';
        echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n");
        echo('<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">' . "\n");
        echo('<head>' . "\n");
        echo('    <meta http-equiv="Content-Type" content="text/html; charset=' . $encoding_charset . '" />' . "\n");
        echo('    <meta name="author" content="Luca Libralato" />' . "\n");
        echo('    <title>' . $page_title . '</title>' . "\n");
        echo('</head>' . "\n");
        echo('<body>' . "\n");
        echo('<span><a name="top"></a></span>' . "\n");
    }

    function page_footer()
    {
        echo('<span><a name="bottom"></a></span>' . "\n");
        echo('</body>' . "\n");
        echo('</html>');
    }

    function remote_file_exists($dir, $file)
    {
        $ret = exec('ls ' . $dir . ' | grep ' . $file);
        return (!empty($ret));
    }

    ?>

  • I have highlighted the portion of codes you will need to adjust, in particular you need to edit the remote folder where the files are $folder_src = 'http://www.targetsite.com/'; and the base name of the file $filename_base_src = 'file_';
  • After having edited the file, you need to create a subfolder called files in the folder you just created (if you have created a folder called downloader, you will then have this path: downloader/files): make sure the files folder has CHMOD 0777 permissions.
  • If everything is fine you can then launch the file in your browser and just wait that it finishes to download all your files!


Enjoy!
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post Re: PHP Files Downloader (Needs A Files Sequence Or List) 
 
Isn't that slow ? I can't remember exactly but cross-domain request are slow in PHP (and most because of the server) AFAIK.
 



 
InformproSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: PHP Files Downloader (Needs A Files Sequence Or List) 
 
Do you think is faster clicking on 327 files manually?
 




____________
Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
 
Mighty GorgonSend private messageSend e-mail to userVisit poster's website  
Back to topPage bottom
Reply with quote Download Post 
Post Re: PHP Files Downloader (Needs A Files Sequence Or List) 
 
Surely not, but using a real langage should be faster, even just for copying. I may benchmark if I find time to update my os then install VS.
 



 
InformproSend private message  
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events


  

 

  cron