Bonjour voila ma question j'utilise un script permettant de ce connecter a mon ftp pour prendre des fichiers et les changer de place pour les mettre sur mon site .
De manière concrète sur mon FTP il y a des source tv (enregistrement de jeux en ligne) certains adversaires les veulent mon script ce connecter donc au serveur prend les fichier les zip et les envoient sur mon site...
Petit problème les fichier sur le serv sont nommé Cc_de_inferno_11-03-2011_22-52-24.dem et je voudrais qu'ils s'appellent 2011-03-11_22-52-24_Cc_de_inferno.zip afin qu'ils se classent dans le bon ordre
voici le script utilisé pourriez vous me donnez une ligne de commande permettant de faire ceci et me dire ou la mettre merci...
<?php
if ( empty($ftp_dir) | empty($dest_dir)) {
die("<center>Désolé votre parametrage n'est pas correct<br>Veuillez éditer le fichier.</center> \n" );
}
$webpage = basename($_SERVER['PHP_SELF']);
global $webpage;
$page = $_GET['page'];
?>
<div style="text-align: center;">
<p style="font-size: medium; font-weight: bold;"><?php echo $name; ?></p>
<FORM method="POST" action="<?php echo $PHP_SELF; ?>">
<input type="submit" name="action" value="refresh" />
</FORM>
</div>
<?php
if(isset($_POST["action"])) {
$action = $_POST["action"];
switch($action) {
case "refresh";
getfiles($dest_dir, $ftp_dir);
printfiles($dest_dir,$url);
break;
}
}
else {
printfiles($dest_dir,$url);
}
?>
</body>
</html>
<?php
function getfiles($dest_dir, $ftp_dir) {
global $ftp_server , $ftp_user_name , $ftp_user_pass , $ftp_root, $del, $delage, $zipfile;
// Création de la connexion
$conn_id = ftp_connect($ftp_server);
// Authentification avec nom de compte et mot de passe
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Vérification de la connexion
echo "<div align=\"center\"> \n";
if ((!$conn_id) || (!$login_result)) {
die ("Connexion ftp " . $ftp_server . " non possible ! \n" );
} else {
echo "Connexion ftp ok!... ";
$dir = $ftp_dir;
//echo "<center>ftp dir : " . $dir . " </center> \n";
$contents = ftp_nlist($conn_id, $dir);
echo "Analyse du repertoire ftp... Veuillez patienter... \n" ;
foreach($contents as $file){
$lenght = strlen($ftp_dir);
$get_file = substr($file, $lenght);
$ext = pathinfo($file, PATHINFO_EXTENSION);
// Téléchargement des fichiers dont l'extension est .dem depuis le repertoire $ftp_dir
if ($ext == 'dem') {
if (!file_exists($dest_dir.$get_file)) {
echo "<center> File get : " . $file . " </center> \n" ;
$buff = ftp_mdtm($conn_id, $file);
$today = MkTime(Date("h,i,s,m,d,Y" ));
$days = number_format((($today - $buff)/86400), 1);
///echo "Fichier en téléchargement : " . $get_file . " " . date("d.m.Y H:i", $buff) . ", Match effectué il y a : " . $days . " jr(s) <br> \n" ;
ftp_get($conn_id, $dest_dir.$get_file, $dir.$get_file,FTP_BINARY);
if ($zipfile == "1" ) {
echo "<center>File zip :" . $dest_dir.$get_file . "\n";
$zip = new ZipArchive();
$filename = "./$get_file.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("Impossible d'ouvrir <$filename>\n" );
}
$zip->addFile($dest_dir.$get_file);
$zip->close();
chmod($dest_dir.$get_file . ".zip", 0755);
unlink($dest_dir.$get_file);
echo "Zip done \n<br>";
}
$i = $i + 1;
//effacement si option choisie dans le parametrage
if ( $del == "1" ) {
if (ftp_delete($conn_id, $file)) {
echo "File delete: " . $file. " done<br> \n";
}
}
}
}
}
if ($i == "" ) {
echo "Aucun nouveau fichier à télécharger. \n";
} else {
echo " " . $i . " nouveau(x) fichier(s) téléchargés(s). \n";
}
ftp_quit($conn_id); //deconnexion du ftp
echo "Traitement terminé. </div> \n";
}
}
function printfiles($dest_dir,$url) {
global $limit, $webpage, $page;
$dir = @opendir($dest_dir);
while ($file = readdir($dir)) {
$ext = pathinfo($dest.$file, PATHINFO_EXTENSION);
// placement des fichiers .dem dans un tableau pour pouvoir les trier
if ($ext == 'dem' || $ext == 'zip') {
$ListFiles[$i]=$file;
$i++;
}
}
closedir($dir);
echo "<div align=\"center\"> \n";
// tri par ordre decroissant - fonction rsort
if(count($ListFiles)!=0) {
rsort($ListFiles);
}
else {
die("Il n'y a actuellement pas de fichier dans le repertoire de destination. \n" );
}
// affiche les fichiers par ordre alphabetique decroissant dans des tables
$total_pages = floor(count($ListFiles)/$limit) +1 ;
$pagination = pagination($total_pages,$page);
if ($page == "" ) {
$page = 1;
}
$i = (($page - 1) * $limit) ;
echo "Nombre total de fichiers : " . count($ListFiles) . " \n";
//echo "limit = " . $limit . ", page = " . $page . ", i = " . $i . " <br> \n";
echo "<table width=\"90%\"> \n" ;
echo "<tr><td width=\"80%\"><b> Filename <b></td><td width=\"20%\" align=\"center\"><b> Filesize(Mb) <b></td></tr> \n" ;
if ( count($ListFiles) > $limit ) {
while ( $i < ($page * $limit) && $i < count($ListFiles)) {
echo '<tr><td width="80%"><a href="' . $url.$ListFiles[$i] . '">' . $ListFiles[$i]. '</a></td><td width="20%" align="center" >' . number_format(filesize($dest_dir.$ListFiles[$i])/1000000, 1) . '</div></td></tr>',"\n";
$i++;
}
}
if ( count($ListFiles) <= $limit ) {
while ( $i < count($ListFiles) ) {
echo '<tr><td width="80%"><a href="' . $url.$ListFiles[$i] . '">' . $ListFiles[$i]. '</a></td><td width="20%" align="center" >' . number_format(filesize($dest_dir.$ListFiles[$i])/1000000, 1) . '</div></td></tr>',"\n";
$i++;
}
}
echo "</table> \n";
echo "<div align=\"center\">" . $pagination . "</div> \n";
echo "Free script from Jenlain - <a href=\"http://www.chti-team.fr\" target=\"_blank\">www.chti-team.fr</a>\n";
echo "</div> \n";
}
function pagination($total_pages,$page){
//pagination_six
global $webpage;
$pagination = '<div class="page_numbers">
<ul>';
if($total_pages!=1){
//the total links visible
$max_links=10;
//$max links_marker is the top of the loop
//$h is the start
$max_links_marker = $max_links+1;
$h=1;
//$link_block is the block of links on the page
//When this is an integer we need a new block of links
$link_block=(($page-1)/$max_links);
//if the page is greater than the top of th loop and link block
//is an integer
if(($page>=$max_links_marker)&&(is_int($link_block))){
//reset the top of the loop to a new link block
$max_links_marker=$page+$max_links;
//and set the bottom of the loop
$h=$max_links_marker-$max_links;
$prev=$h-1;
}
//if not an integer we are still within a link block
elseif(($page>=$max_links_marker)&&(!is_int($link_block))){
//round up the link block
$round_up=ceil($link_block);
$new_top_link = $round_up*$max_links;
//and set the top of the loop to the top link
$max_links_marker=$new_top_link+1;
//and the bottom of the loop to the top - max links
$h=$max_links_marker-$max_links;
$prev=$h-1;
}
//if greater than total pages then set the top of the loop to
// total_pages
if($max_links_marker>$total_pages){
$max_links_marker=$total_pages+1;
}
//first and prev buttons
if($page>'1'){
$pagination.='<li class="current"><a href="'.$webpage.'?page=1">First</a></li>
<li class="current"><a href="'.$webpage.'?page='.($page-1).'">Prev</a></li>';
}
//provide a link to the previous block of links
$prev_start = $h-$max_links;
$prev_end = $h-1;
if($prev_start <=1){
$prev_start=1;
}
$prev_block = "Pages $prev_start to $prev_end";
if($page>$max_links){
$pagination.='<li class="current"><a href="'.$webpage.'?page='.$prev.'">'.$prev_block.'</a></li>';
}
//loop through the results
for ($i=$h;$i<$max_links_marker;$i++){
if($i==$page){
$pagination.= '<li><a class="current">'.$i.'</a></li>';
}
else{
$pagination.= '<li><a href="'.$webpage.'?page='.$i.'">'.$i.'</a></li>';
}
}
//provide a link to the next block o links
$next_start = $max_links_marker;
$next_end = $max_links_marker+$max_links;
if($next_end >=$total_pages){
$next_end=$total_pages;
}
$next_block = "Pages $next_start to $next_end";
if($total_pages>$max_links_marker-1){
$pagination.='<li class="current"><a href="'.$webpage.'?page='.$max_links_marker.'">'.$next_block.'</a></li>';
}
//link to next and last pages
if(($page >="1" )&&($page!=$total_pages)){
$pagination.='<li class="current"><a href="'.$webpage.'?page='.($page+1).'">Next</a></li>
<li class="current"><a href="'.$webpage.'?page='.$total_pages.'">Last</a></li>';
}
}
//if one page of results
else{
$pagination.='<li><a href="" class="current">1</a></li>';
}
$pagination.='</ul>
</div>';
return($pagination);
}
?>