1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<?php
$ftp_pathfile ="";
session_start();
require("files/config.php");
error_reporting(0);
set_time_limit(0);
$conn_id = ftp_connect($ftp_host, 22, 150);
$login_result = ftp_login($conn_id, $ftp_username, $ftp_password);
$mode = ftp_pasv($conn_id, TRUE);
if ((!$conn_id) || (!$login_result)) {
echo "La connexion FTP a échoué!";
echo "Tentative de connexion au serveur $ftp_host pour l'utilisateur $ftp_username";
exit;
} else {
//echo "Connexion au serveur $ftp_host pour l'utilisateur $ftp_username".'<br>';
}
//echo "Dossier courant : " . ftp_pwd($conn_id)."\n";
if (ftp_chdir($conn_id, ".")) {
echo "Le dossier courant est maintenant: /".$ftp_pathfile.'<br>';
} else {
//echo "Impossible de changer de dossier\n";
}
echo '<hr>';
$folder_exists = (!is_dir('ftp://'.$ftp_username.':'.$ftp_password.'@'.$ftp_host.':22/'.$ftp_pathfile)) ? false : true;
if($folder_exists == false)
{
echo "<b>Error:</b> Le fichier spécifié n'existe pas.";
exit;
}
$rawfiles = ftp_rawlist($conn_id, $ftp_pathfile, true);
ftp_close($conn_id);
$structure = array();
$arraypointer = &$structure;
foreach ($rawfiles as $rawfile) {
if ($rawfile[0] == '/') {
$paths = array_slice(explode('/', str_replace(':', '', $rawfile)), 1);
$arraypointer = &$structure;
foreach ($paths as $path) {
foreach ($arraypointer as $i => $file) {
if ($file['text'] == $path) {
$arraypointer = &$arraypointer[ $i ]['children'];
break;
}
}
}
} elseif(!empty($rawfile)) {
$info = preg_split("/[\s]+/", $rawfile, 9);
$arraypointer[] = array(
//'text' => $info[8],
//'isDir' => $info[0]{0} == 'd',
//'size' => byteconvert($info[4]),
//'chmod' => chmodnum($info[0]),
//'date' => strtotime($info[1] . ' ' . $info[2] . ' ' . $info[3]),
'raw' => $info
// the 'children' attribut is automatically added if the folder contains at least one file
);
}
}
$temp_path_file=array();
for($a=0;$a<sizeof($structure);$a++){
$temp_path_file[]="ftp://".$ftp_username.":".$ftp_password."@".$ftp_host.":22"."/".$ftp_pathfile."/".$structure[$a]['raw'][3];
$file_link = 'files/download.php?file='.base64_encode($temp_path_file[$a]);
}
// in $structure is all the data
var_dump($structure);
//var_dump($temp_path_file);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<style>body{font-family: "Courier New", Courier, monospace; padding: 0; margin: 0;}</style>
</head>
<body>
<div class="bs-example">
<table class="table table-striped" border=1>
<thead>
<tr>
<th>Ligne</th>
<th>Nom</th>
<th>Date</th>
<th>Taille</th>
<th>Thumbnail</th>
</tr>
</thead>
<tbody>
<?php
for($a=0;$a<sizeof($structure);$a++){
If (pathinfo($structure[$a]['raw'][3], PATHINFO_EXTENSION) == "jpg"){
echo '<tr>
<td>'.$ftp_pathfile.'</td>
<td>'.$structure[$a]['raw'][3].'</td>
<td>'.$structure[$a]['raw'][0].'</td>
<td>'.$structure[$a]['raw'][2].'</td>
<td><img src="'.$file_link[$a]['raw'][3].'" width="320" height="240" title="'.$structure[$a]['raw'][3].'"></td>
</tr>';}}
?>
</tbody>
</table>
</div>
</body>
</html> |
Partager