TheNewOne Posted January 21, 2008 Share Posted January 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/ Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 well... your bestbet... would be to grab all the files into an array using glob() and then filtering them down from there... Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445457 Share on other sites More sharing options...
marcus Posted January 21, 2008 Share Posted January 21, 2008 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"; } } } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445460 Share on other sites More sharing options...
TheNewOne Posted January 21, 2008 Author Share Posted January 21, 2008 that script helps me, but how can i use it for an url? Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445463 Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 if you do use that script... be aware that it'll prolly crash because them loops do have a max lifespan... Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445475 Share on other sites More sharing options...
marcus Posted January 21, 2008 Share Posted January 21, 2008 I completed the loop in about 4 minutes. 1,607,040 results. lol Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445477 Share on other sites More sharing options...
TheNewOne Posted January 21, 2008 Author Share Posted January 21, 2008 i have one problem with the script. noo, i mean it works well. but how can i use it with an url? and can the script automatically download it then? can you plz do that last thing for me? Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445485 Share on other sites More sharing options...
Barand Posted January 21, 2008 Share Posted January 21, 2008 And if there are 1,000 files with various dates between 2005 and now, do you want to download all of them? Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445488 Share on other sites More sharing options...
TheNewOne Posted January 21, 2008 Author Share Posted January 21, 2008 yes. if possible Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445490 Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445505 Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445509 Share on other sites More sharing options...
Barand Posted January 21, 2008 Share Posted January 21, 2008 "localhost" isn't usually very remote. Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445512 Share on other sites More sharing options...
rhodesa Posted January 21, 2008 Share Posted January 21, 2008 "localhost" isn't usually very remote. touché Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445516 Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 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... :-) Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445517 Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 either way... you have an array full of available filenames... and i'm not sure if php can force download more then one file at a time... but i BELIEVE it can archive them all(zip or whatever), and then download that one...? Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445521 Share on other sites More sharing options...
TheNewOne Posted January 21, 2008 Author Share Posted January 21, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445582 Share on other sites More sharing options...
TheNewOne Posted January 22, 2008 Author Share Posted January 22, 2008 help? anyone? Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-445936 Share on other sites More sharing options...
TheNewOne Posted January 23, 2008 Author Share Posted January 23, 2008 come on guys. all i need is that the script downloads the file when it finds it. please Quote Link to comment https://forums.phpfreaks.com/topic/87099-newbie-needs-help-with-an-php-idea/#findComment-447021 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.