Contenu fichier téléchargé incorrect

Ffx_Win -  
 Ffx_Win -
Bonjour,

J'ai réalisé un script PHP pour afficher le contenu de fichiers sur un serveur local.
Dans cette page sont générés des liens pointant vers cette page : lors du clic cela déclenche le téléchargement du fichier pointé.
Problème : le contenu est celui de la page visitée et non le document : voici le code :

<?php
function get_parent_folder($path) {
	$items = explode('/', $_GET['path']);
	array_pop($items);
	return implode('/', $items);
}

// Validation des paramètres
require_once 'Zend/Validate.php';

require('../../jessy.inc.php');
$jessy->include_file('html.inc.php');

require('common.php');

$html = new html_doc();
$html->begin('Fichiers');
$html->header();
$html->begin_menu();
echo $html->get_page_header();

isset($_GET['device']) ? $device = $_GET['device'] : $device = 0;

if (isset($_GET['share'])) {
	if (!Zend_Validate::is($_GET['share'], 'Int') /*or !Zend_Validate::is($_GET['share'], 'Between', array(0, $i))*/) {
		echo '<p class="warning">Erreur : identificateur de partage incorrect !</p>';
		exit();
	}
	$path = $devices[$device]['path'] . '/' . $shares[$_GET['share']]['path'] . $_GET['path'];
	
	//modif par BF le 31/05/2010
	switch(strrchr(basename($path), ".")) {
		case ".gz": $type = "application/x-gzip"; break;
		case ".tgz": $type = "application/x-gzip"; break;
		case ".zip": $type = "application/zip"; break;
		case ".pdf": $type = "application/pdf"; break;
		case ".png": $type = "image/png"; break;
		case ".gif": $type = "image/gif"; break;
		case ".jpg": $type = "image/jpeg"; break;
		case ".txt": $type = "text/plain"; break;
		case ".htm": $type = "text/html"; break;
		case ".html": $type = "text/html"; break;
		default: $type = "application/octet-stream"; break;
	}
	//---
	
	if (is_file($path)) {
		$size = filesize($path);
		header("Content-Disposition: attachment; filename=\"" . basename($path) ."\"");
		header("Content-Type: application/force-download; name=\"" . basename($path) ."\"");
		header("Content-Transfer-Encoding: $type\n");
		header("Content-Length: $size");	
		header("Expires: 0");
		header("Cache-Control: no-cache, must-revalidate");
		header("Pragma: no-cache"); 
		readfile($path);
		exit();
	}
}

if (isset($_GET['share'])) {	
  $share = $shares[$_GET['share']];
	echo "<p>" . $share['caption'] . " <span class=\"path\">" . utf8_decode($_GET['path']) . "</span> sur " . $devices[$device]['caption'] . "</p><hr>\n";
	if (!file_exists($path)) {
		echo '<p class="warning">Erreur : chemin incorrect !</p>';
		if (user_is_admin()) {
      echo "<pre>\n";
      echo $path . "\n";
      echo "</pre>\n";
    }
	} else {
		$files = @scandir($path);
		if ($files) {
			echo "<ul class=\"files\">\n";
			if (!empty($_GET['path'])) {
				$parent_folder = get_parent_folder($_GET['path']); 
				echo "<li class=\"up\"><a href=\"?device=$device&share={$_GET['share']}&path=$parent_folder\">Retour au dossier parent</a></li>\n";
			} else {
				echo "<li class=\"up\"><a href=\"?device=$device\">Retour aux partages</a></li>\n";
			}
			foreach ($files as $file) {
				if (($file != '.') and ($file != '..')) {
					$abs_file_path = $path . '/' . $file;
					$rel_file_path = $_GET['path'] . '/' . $file; 
					if (is_dir($abs_file_path)) {
						$cls = 'folder';
						echo "<li class=\"$cls\"><a href=\"?device=$device&share={$_GET['share']}&path=" . urlencode($rel_file_path). "\">". utf8_decode($file) . "</a></li>\n";
					} else {
						$cls = 'file';
						echo "<li class=\"$cls\"><a href=\"?device=$device&share={$_GET['share']}&path=" . urlencode($rel_file_path). "\">". utf8_decode($file)
						  . "</a>";
					  if ($share['backup']) {
					    echo " - <a class=\"action\" href=\"view_old_versions.php?device=$device&share={$_GET['share']}&path=" . urlencode($rel_file_path). "\">Anciennes versions</a>";
					  }
					  echo "</li>\n"; 
					}			
				}
			}
			echo "</ul>\n";
		} else {
			echo "<ul class=\"files\">\n";
			if (!empty($_GET['path'])) {
				$parent_folder = get_parent_folder($_GET['path']); 
				echo "<li class=\"up\"><a href=\"?share={$_GET['share']}&path=$parent_folder\">Retour au dossier parent</a></li>\n";
			} else {
				echo "<li class=\"up\"><a href=\"?\">Retour au dossier parent</a></li>\n";
			}
			echo "</ul>\n";
			echo '<p class="warning">Une erreur est survenue lors de la lecture du dossier !</p>';
		}
	} 
} else { 
	echo "<p>Partages réseau</p><hr>\n";
	echo "<ul class=\"files\">\n";
	foreach($shares as $id => $share) {
	  if ($share['backup']) {
	    echo "<li class=\"share_with_backup\"><a href=\"?device=$device&share=$id\">{$share['caption']}</a></li>\n";
	  } else {
	    if ($device == 0) {
	      echo "<li class=\"share\"><a href=\"?device=$device&share=$id\">{$share['caption']}</a></li>\n";
	    }
	  }
		
	}
	echo "</ul>\n";
	echo "<form method=\"get\">\n";	
	echo '<label for="device">Périphérique : </label>';
	echo "<select name=\"device\">\n";
	foreach ($devices as $key => $value) {
	   echo "<option value=\"$key\"";
	   if ($device == $key) {
	     echo ' selected="selected"';
	   }
	   echo ">{$value['caption']}</option>\n";	
	}
	echo "</select>\n";
	echo "<input type=\"submit\" value=\"OK\">";
	echo "</form>\n";
	
	if ($device == 1) {
    mountDisk($devices[$device]['mount'], $devices[$device]['path']);
  }
}

$html->end_menu();
$html->footer();
$html->end();


Pourriez vous m'indiquer quoi retravailler (mes headers fonctionnent avec une autre page de téléchargement de fichier du même type.)

Merci d'avance pour vos réponses.
A voir également:

1 réponse

Ffx_Win
 
Une petite aide svp ?
1