Aller au contenu
View in the app

A better way to browse. Learn more.

Next

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[RESOLU][php]Forcer un telechargement

Featured Replies

Posté(e)

bonjour,

voila j'ai ce code :

header("Content-disposition: attachment; filename=$filename");
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($filename));
header("Pragma: no-cache");
header("Expires: 0");
readfile($filename);

il fonctionne parfaitement sur un dedie en php4

par contre sur un autre dedie en php5, le telechargement se bloque a 2 mo

apres multiples recherche dans le fichier php.ini rien n'y fait

j'ai fait le test sur un mutualise ou le problème et le meme

http://90pack.ovh.net/~mostik/

le fichier dl.php et dl.php5 sont identiques, seule l'extention a ete change

resultat :

le fichier dl.php fonctionne parfaitement

le fichier dl.php5 ne fonctionne pas , le telechargement est bloque a 2 mo exactement comme sur mon dedie

auriez vous une idee ?

merci

Modifié par kenji

Posté(e)

Ca ressemble à un probleme de config du memory_limit dans le php.ini de php5.

Si tu ne veux pas avoir ce genre de probleme je te conseille de tronquer ton readfile avec un feof/echo.

Plusieurs exemples sur http://php.net/readfile

Posté(e)
  • Auteur

bon finalement le code pour que cela fonctinne est celui ci :

<?php
if(isset($_GET["file"])){$file = $_GET["file"]; }

function dl_file_resume($file){

  //First, see if the file exists
  if (!is_file($file)) { die("<b>404 File not found!</b>"); }

  //Gather relevent info about file
  $len = filesize($file);
  $filename = basename($file);
  $file_extension = strtolower(substr(strrchr($filename,"."),1));
  $ctype="application/force-download";


  //Begin writing headers
  header("Cache-Control:");
  header("Cache-Control: public");
 
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
//if your filename contains underscores, you can replace them with spaces
header("Content-disposition: attachment; filename=$filename");
header($header );
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: binary");
$size=filesize($file);
//check if http_range is sent by browser (or download manager)
if(isset($_SERVER['HTTP_RANGE'])) {
list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
//if yes, download missing part
 str_replace($range, "-", $range);
 $size2=$size-1;
 $new_length=$size2-$range;
 header("HTTP/1.1 206 Partial Content");
 header("Content-Length: $new_length");
 header("Content-Range: bytes $range$size2/$size");
}else{
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size2);
}
//open the file
$fp=fopen("$file","r");
//seek to start of missing part
fseek($fp,$range);
//start buffered download
while(!feof($fp)){
//reset time limit for big files
set_time_limit(0);
print(fread($fp,1024*8));
 flush();
}
fclose($fp);
  exit;
}

dl_file_resume($file);
?>

pour le cas ou d'autres rencontrerait ce problème

:cartonrouge:

Modifié par kenji

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.