Zdravím
Potřeboval bych napsat skript který v definovaném adresáři najde soubor *.jpg který je nejčerstvější a přejmenuje ho a ten originál smaže díky
Moderátor: Moderátoři Živě.cz
<?php
$dir = "IPkamera/snap";
chdir($dir);
rename ("Schedule_20141213-104648.jpg","obrazek.jpg");
?>
<?php
$dir = "IPkamera2/snap";
$pattern = '\.(zip|ZIP|pdf|jpg|JPG)$'; // check only file with these ext.
$newstamp = 0;
$newname = "";
$new = "obraz.jpg";
if ($handle = opendir($dir)) {
while (false !== ($fname = readdir($handle))) {
// Eliminate current directory, parent directory
if (ereg('^\.{1,2}$',$fname)) continue;
// Eliminate other pages not in pattern
if (! ereg($pattern,$fname)) continue;
$timedat = filemtime("$dir/$fname");
if ($timedat > $newstamp) {
$newstamp = $timedat;
$newname = $fname;
}
}
}
closedir ($handle);
// $newstamp is the time for the latest file
// $newname is the name of the latest file
// print last mod.file - format date as you like
//$stare = $newname;
//$dir = "/IPkamera2/snap";
//$sa = "IPkanera2/snap".$newname;
rename ("mujfrehosting.8u.cz/web/IPkanera2/snap/".$newname,"mujfrehosting.8u.cz/web/IPkanera2/snap/".$new);
echo $newname;
//print $newname . " - " . date( "Y/m/d", $newstamp);
?>
<?php
$g ="Schedule_20141213-104618.jpg";
rename($g,"obraz.jpg")
?>
Just_jo píše:Odpověď: v části "rename" je špatná cesta - zapněte si zobrazování chyb z php.
Odzkoušel jsem to a u mě to chodí po opravě cest u rename
Uživatelé procházející toto fórum: Žádní registrovaní uživatelé a 0 návštevníků