Simple rename file problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wlbragg
Forum Newbie
Posts: 8
Joined: Fri Jan 25, 2008 12:40 am
Location: Kansas, US

Simple rename file problem

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple rename file problem

Post 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. ;)
(#10850)
wlbragg
Forum Newbie
Posts: 8
Joined: Fri Jan 25, 2008 12:40 am
Location: Kansas, US

Re: Simple rename file problem

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple rename file problem

Post by Christopher »

Batch file or just run it directly "php myscript.php". See the manual for CLI.
(#10850)
wlbragg
Forum Newbie
Posts: 8
Joined: Fri Jan 25, 2008 12:40 am
Location: Kansas, US

Re: Simple rename file problem

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Simple rename file problem

Post by Christopher »

(#10850)
wlbragg
Forum Newbie
Posts: 8
Joined: Fri Jan 25, 2008 12:40 am
Location: Kansas, US

Re: Simple rename file problem

Post by wlbragg »

Thanks
Post Reply