par
hpl76 » 28 oct. 2008, 16:36
Le code final est le suivant :
<?php
if(!empty($_GET["id"])){
$nom = substr($_GET["id"],2,3).substr($_GET["id"],7,3).substr($_GET["id"],29,3);
if (file_exists($nom.'.pdf')) {
$mdnom = substr(md5($nom),0,10);
switch(strrchr(basename($nom), ".")) {
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;
}
header("Content-disposition: attachment; filename=".$mdnom.'.pdf');
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: $type\n");
header("Content-Length: ".filesize($nom.'.pdf'));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($nom.'.pdf');
}else{
header ("location:index.php");
}
}else{
header ("location:index.php");
}
?>
Ce que je ne comprends pas c'est pouquoi cela ne fonctionne pas pour 5% des cas...
Bien à vous !
hpl76
Le code final est le suivant :
[php]<?php
if(!empty($_GET["id"])){
$nom = substr($_GET["id"],2,3).substr($_GET["id"],7,3).substr($_GET["id"],29,3);
if (file_exists($nom.'.pdf')) {
$mdnom = substr(md5($nom),0,10);
switch(strrchr(basename($nom), ".")) {
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;
}
header("Content-disposition: attachment; filename=".$mdnom.'.pdf');
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: $type\n");
header("Content-Length: ".filesize($nom.'.pdf'));
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
readfile($nom.'.pdf');
}else{
header ("location:index.php");
}
}else{
header ("location:index.php");
}
?>[/php]
Ce que je ne comprends pas c'est pouquoi cela ne fonctionne pas pour 5% des cas...
Bien à vous !
hpl76