Renvoi d'une erreur script php

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Renvoi d'une erreur script php

Re: Renvoi d'une erreur script php

par Ryle » 05 sept. 2011, 21:10

Cela signifie que ta variable $contents ne contient pas un tableau php d'où le message d'erreur. Il te faut donc contrôler ce que retourne ton ftp_nlist() et vérifier que celui-ci fait bien ce que tu attends (ou chercher les erreurs éventuelles)

Renvoi d'une erreur script php

par JcLoD » 05 sept. 2011, 20:19

Salut a tous :) ,

Alors voila j'ai un bug avec un de mes script en php donc j'aurais besoin de votre aide pour mon site : http://nightskill.mtxserv.fr/notaccesviewvg.php
Mon souci c'est que le script si-dessous sert a transferer automatiquement des fichiers d'un ftp à un autre mais il marchait bien jusqu'a aujourd'hui mes maintenant quand je clique sur le bouton actualiser sur le site, il me renvoi une erreur : Warning: Invalid argument supplied for foreach() in /var/www/nightskill.mtxserv.fr/public_html/notaccesview.php on line 154
Et il met qu'aucun nouveau fichier est à télécharger alors qu'il y en a bien un !

Voici le script php:
<?php
// Nom du script : demolist_ftp.php
// Version : editer par JcLoD fonction delete [on], fonction zip [off]
// Date : 27/9/2009                                                                                    
// Auteur : Thierry Vanneste alias jenlain 
// Email : [email protected]
// Licence : GNU GPL http://www.gnu.org/licenses/gpl.txt
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// P A R A M E T R A G E 
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$ftp_server = "88.190.21.207"; // l'adresse ftp du serveur de jeu. Par exemple ftp.verygames.net
$ftp_user_name = "jclod"; // le username ftp par exemple server0000
$ftp_user_pass = "******"; // le password ftp par exemple ********
$ftp_dir = "/home/jclod/service4/css/orangebox/cstrike/"; //le chemin vers le repertoire ftp sur le serveur de jeu où sont stockées les démos, avec un / au debut et à la fin, en general (/games/half-life/cstrike/).  
$dest_dir = "./demos/"; //le chemin vers le repertoire sur le serveur web où seront stockées les démos evc un / au debut et à la fin. Le repertoire doit être inscriptible (chmod 777)
$url = "http://nightskill.mtxserv.fr/demos/"; // l'url vers le répertoire où seront stockées les démos avec un / au bout.
$del = "1"; // Si 1  supprime les fichiers sur le serveur ftp qui sont deja presents sur votre site web 
$limit = "12"; // Nombre de demos affichées par pages
$zipfile = "1"; // Si 1 les fichiers transférés seront compressés. (Pré-requis : php5 avec zlib)
// Pour connaitre le chemin vers la racine de votre serveur web, décommentez les deux lignes suivantes et relancez le fichier
//$root = getenv("DOCUMENT_ROOT") ;
//echo "<center>DOCUMENT_ROOT: " . $root . "</center>"; 
// Pour connaitre le repertoire ftp où sont affichées les démos, utilisez votre logiciel ftp, filezilla ou autre.
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// NE RIEN TOUCHER APRES CETTE LIGNE SI VOUS NE MAITRISEZ PAS LE CODE.
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
<style type="text/css">
<!--
body,td,th { 
	font-family: Arial, Helvetica, sans-serif;
	color: #000000; 
	font-size: 12px; 
}
a:link { 
	color: #000000; 
	text-decoration: none; 
}
a:visited { 
	text-decoration: none; 
	color: #000000; 
}
a:hover { 
	text-decoration: none; 
	color: #FF0000; }
a:active { 
	text-decoration: none; 
	color: #FF0000; }
.page_numbers {
	display:table;           
	padding:0;
	margin:0 auto;
	font-family: arial, helvetica, sans-serif;
	white-space:nowrap;
	list-style-type:none;
}
* html .page_numbers {
	display:inline-block;
	width:1px;
	padding:0 2px;
 }  
.page_numbers li {
	display:table-cell;
 }
* html .page_numbers li {
	display:inline;
}
.page_numbers a {
	display:block;
	padding:0.2em 1em; 
	color:#000000; 
	text-decoration:none;
 }
* html .page_numbers a {
	display:inline-block;
	margin:0 -2px; 
 }
.page_numbers a:hover {
	color:#FF0000; 
	background:#FFFFFF;
 }
a.current {
	color:#000000; 
	background:#FFFFFF;
	cursor:default;
 }
-->
</style>
<!--[if IE]>
<style type="text/css">
.page_numbers  a { display:inline-block; }
.page_numbers ul li {display:inline; }
</style>
<![endif]-->
</head>
<body>

<?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="actualiser" />
</FORM>
</div>

<?php
if(isset($_POST["action"])) {
$action = $_POST["action"];

	switch($action) {
		case "actualiser"; 
			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);	
					$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 - Designed & Edited by JcLoD\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);
}


?>
Merci d'avance pour votre aide :wink:

Cdt JcLoD