Jump to content

Newbie needs help with an php idea


TheNewOne

Recommended Posts

Hi :)

 

I need help with a script that does the following

 

I want to download a file called "test200801012106.jpg"

 

for example: http://localhost/test200801012106.jpg

 

But, the only thing i know it that the file is called test...jpg. i dont know the numbers (which are time and date).

 

So i know the following: http://localhost/test$year$month$day$hour$minute.jpg

 

So... i want to download that file, but what if i dont know the date?

 

Could someone show me how to write a php script, that just trys the dates? and then downloading it with wget, for example.

 

So for example from 2005 on, every month from 01-12, ever day from 01-31, every hour from 01-24 and every minute from 01-60.

 

Is this possible (i know it should, but i just dont know how)

 

Please help me

( I know many of you are good, so please help me with this little problem)

Thx

Link to comment
https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/
Share on other sites

If you really want to check 50,000+ filenames...

 

<?php
for ($a = 2005; $a <= 2008; $a++) { //year
    for ($b = 1; $b <= 12; $b++) { //month
        for ($c = 1; $c <= 31; $c++) { //days
            for ($d = 1; $d <= 24; $d++) { //hours
                for ($e = 1; $e <= 60; $e++) { //minutes
                    if (file_exists("test" . $a . $b . $c . $d . $e . ".jpg")) {
                        echo "Filename: " . "test" . $a . $b . $c . $d . $e . ".jpg exists<br>\n";
                    }
                }
            }
        }
    }
}
?>

personally... i'd do it more like this

 

$files=array_merge(glob('test2005*.jpg'),glob('test2006*.jpg'),glob('test2007*.jpg'),glob('test2008*.jpg'));

 

so there, we have every jpg file that starts with test2005-2008 all in a single array... and probably FAR faster then using loops...

personally... i'd do it more like this

 

$files=array_merge(glob('test2005*.jpg'),glob('test2006*.jpg'),glob('test2007*.jpg'),glob('test2008*.jpg'));

 

so there, we have every jpg file that starts with test2005-2008 all in a single array... and probably FAR faster then using loops...

glob() will not work on remote files. the loop is the only way if you are using remote files.

personally... i'd do it more like this

 

$files=array_merge(glob('test2005*.jpg'),glob('test2006*.jpg'),glob('test2007*.jpg'),glob('test2008*.jpg'));

 

so there, we have every jpg file that starts with test2005-2008 all in a single array... and probably FAR faster then using loops...

glob() will not work on remote files. the loop is the only way if you are using remote files.

 

i realize that... and "TheNewOne" never said the files were remote... and localhost... is local... :-)

<?php
for ($a = 2005; $a <= 2008; $a++) { //year
    for ($b = 1; $b <= 12; $b++) { //month
        for ($c = 1; $c <= 31; $c++) { //days
            for ($d = 1; $d <= 24; $d++) { //hours
                for ($e = 1; $e <= 60; $e++) { //minutes
                    if (file_exists("test" . $a . $b . $c . $d . $e . ".jpg")) {
                        echo "Filename: " . "test" . $a . $b . $c . $d . $e . ".jpg exists<br>\n";
                    }
                }
            }
        }
    }
}
?>

 

this code is very good. but what i need now is that it downloads every file it finds. there wont be more than 5 files. but they are remote, thats why i have to do it that way...

 

plz help me with the downloadpart.

 

and question: if (file_exists("test" . $a . $b . $c . $d . $e . ".jpg"))    can i insert an url there, too (at the test word)? cos thats what i need.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.