Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.