Page 1 of 1

Simple rename file problem

Posted: Tue Mar 11, 2008 3:03 pm
by wlbragg
I hope this isn't something stupid I overlooked.

I am renaming image[integer].jpg cam capture files using

Code: Select all

 
$startingWrite=0;
$begRead=0;
$endRead=240000;
 
for ($i=$startingWrite,$inc=0;$inc<($endRead+1);$i++,$inc++) {
    $IMAGE_SOURCE = ("image".$begRead.$inc).".jpg";
    if (!fopen($IMAGE_SOURCE,"rb")) 
        $i--;
    else {
        $OUTPUT_FILE = "image".$i.".jpg";
        rename($IMAGE_SOURCE, $OUTPUT_FILE);
    }
}
 
$begRead and $endRead values are actually coming from another function that is determining the first number and the last number of the range of numbers that need to be renamed. The range of numbers is based on a 24 hour double digit time down to the second so the values are anywhere from 10000 to 240000 more or less as I trim the hour positions that start with 0. I hard coded $begRead and $endRead to debug.

It bombs if $endRead is larger than 37663. Is this some sort of PHP integer limit or a connection timeout limit? It doesn't appear to be a timeout problem as I tried
$begRead=240000;
$endRead=245000;
with the same resutls. I thought maybe PHP needed dos 8+3 file naming but that wasn't it either.

Anyone know?

Thanks in advance if you do!

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 3:32 pm
by Christopher
Are you running this from the command line or through a web server? Using the command line would be recommended to process 240,000 files. ;)

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 4:17 pm
by wlbragg
Web server, you think it's a timeout issue? I never used the command line. But that would make sense. I could use a batch file to run it I suppose?

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 4:36 pm
by Christopher
Batch file or just run it directly "php myscript.php". See the manual for CLI.

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 5:02 pm
by wlbragg
By the way, the program is actually only opening and renaming less than 300. The range of numbers the file name can be is huge, thus 10000-240000, because it's time related down to the second but I'm only capturing images every 10 minutes and processing them at 24 hr intervals thus the 300 or less. Calculating 240000 in a loop is nothing. The only thing that might be a problem with that is the if the

Code: Select all

if (!fopen($IMAGE_SOURCE,"rb")) {}
is the problem. I don't know what overhead that creates in the process. You still think it's a timeout? Is there any other way to check to see if there is a file that wont cause a problem?
I really want to do this through the web server because that's where the automation of this process can be initiated by the user.

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 5:17 pm
by Christopher

Re: Simple rename file problem

Posted: Tue Mar 11, 2008 9:21 pm
by wlbragg
Thanks