I want to change the name of a file. The source filename is changing all the time. The produced name mus be fixed. Here is mij script:
<?php
$directory = '/public_html/Weercam/FI9853EP_00626EA2E6A9/snap/';
foreach (glob($directory."*.jpg") as $filename) {
$file = realpath($filename);
rename($file, str_replace(".jpg","test.gif",$file));
}
?>
It works. BUT the name shoud be only test.gif. Now it makes the name like: abcdefghtest.gif
I tried to use the script on the server. It works fine, onle the outcoming name is wrong
CodePudding user response:
str_replace only replaces part of the string, leaving the rest. Maybe you're looking for rename($file, "test.gif");
CodePudding user response:
you want to use the rename function in a different way in this case:
rename($file, "test.gif");
syntax:
rename(oldname, newname, context)
context is an optional parameter which specifies the behavior of the stream .