Suppression de fichier après téléchargement

Résolu
girardcimpa Messages postés 7 Date d'inscription jeudi 30 juillet 2009 Statut Membre Dernière intervention 3 août 2011 - 3 sept. 2009 à 10:58
cs_bolox Messages postés 9 Date d'inscription lundi 21 février 2005 Statut Membre Dernière intervention 6 mars 2013 - 6 mars 2013 à 08:30
Bonjour

A partir d'un formulaire je crée un fichier zip et propose à l'utilisateur de l'enregistrer.
Mon problème : le fichier zip est créé localement sur le serveur et je n'arrive pas à trouver un moyen de le supprimer après l'enregistrement.

Une partie du source :
<?php

require_once( 'core.php' );
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path . 'file_api.php' );
require_once( $t_core_path . 'csv_api.php' );
require_once( $t_core_path . 'bug_api.php' );
$f_bug_arr = gpc_get_int_array( 'bug_arr', array() );
$file_list_bug = array();
$file_list_name = array();
$filenom = current_user_get_field( 'username' ) .'-'. date('dmY').'.zip';
$zip = new ZipArchive();
if ($zip->open($filenom, ZIPARCHIVE::OVERWRITE) == TRUE) {
$filecsv = create_csv_file($f_bug_arr);
$zip->addFile($filecsv);
foreach ($f_bug_arr as $t_bug_id) {
$dir_bug=bug_format_id($t_bug_id);
$zip->addEmptyDir($dir_bug);
$file_list_bug = file_attachments_liste ( $t_bug_id,1 );
$file_list_name = file_attachments_liste ( $t_bug_id,2 );
for ($i = 0; $i < count($file_list_bug); $i++) {
$zip->addFile($file_list_bug[$i],$dir_bug.'\\'.$file_list_name[$i]);
}
// mise à jour du status
$t_bug_data =bug_get( $t_bug_id,true);
$t_bug_data->status = ESTIMATED;
bug_update( $t_bug_id, $t_bug_data );
}
$zip->close();
unlink($filecsv);

// # flush output buffer to protect download
@ob_end_clean();
// # Make sure that IE can download the attachments under https.
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize($filenom));
header('Content-Type: application/x-zip-compressed');
// # Added Quotes (") around file name.
header( 'Content-Disposition: attachment; filename="' . $filenom . '"' );
header( 'Content-Description: Download Data' );
header("Expires: 0");
// # To fix an IE bug which causes problems when downloading
// # attached files via HTTPS, we disable the "Pragma: no-cache"
// # command when IE is used over HTTPS.
if ( ( "on" == $_SERVER["HTTPS"] ) && preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) {
# Suppress "Pragma: no-cache" header.
} else {
header( 'Pragma: no-cache' );
}
readfile( $filenom );
exit;
}
Merci d'avance, 2 jours que je cherche une solution...

8 réponses

Tonio_35 Messages postés 567 Date d'inscription mercredi 4 octobre 2006 Statut Membre Dernière intervention 30 août 2011 11
3 sept. 2009 à 14:54
T as essayé le unlink($filenom ); après le readfile( $filenom ); ?

_________________________________
Min iPomme
3
Tonio_35 Messages postés 567 Date d'inscription mercredi 4 octobre 2006 Statut Membre Dernière intervention 30 août 2011 11
3 sept. 2009 à 14:13
_________________________________
Min iPomme
0
Tonio_35 Messages postés 567 Date d'inscription mercredi 4 octobre 2006 Statut Membre Dernière intervention 30 août 2011 11
3 sept. 2009 à 14:14
Oups désolé pour ce post vide...

T'as pas moyen avec ta lib de zip de l'envoyer direct vers la sortie plutot que de créer un fichier ?


_________________________________
Min iPomme
0
girardcimpa Messages postés 7 Date d'inscription jeudi 30 juillet 2009 Statut Membre Dernière intervention 3 août 2011
3 sept. 2009 à 14:46
Apparemment non.

Si je ne fais pas $zip->open($filenom, ZIPARCHIVE::OVERWRITE)ou si je fais juste $zip->open($filenom), le fichier enregistré est vide
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
girardcimpa Messages postés 7 Date d'inscription jeudi 30 juillet 2009 Statut Membre Dernière intervention 3 août 2011
3 sept. 2009 à 14:58
Merci ça marche.

Je pensais que rien n'était exécuter après readfile (débutant en php)
0
Tonio_35 Messages postés 567 Date d'inscription mercredi 4 octobre 2006 Statut Membre Dernière intervention 30 août 2011 11
3 sept. 2009 à 15:04
De rien, met sélectionne la réponse acceptée pour plus de lisibilité...


Bonne continuation...

_________________________________
Min iPomme
0
Tonio_35 Messages postés 567 Date d'inscription mercredi 4 octobre 2006 Statut Membre Dernière intervention 30 août 2011 11
3 sept. 2009 à 15:17
Comment j'écris moi... Excusez ma dysorthographie passagère

_________________________________
Min iPomme
0
cs_bolox Messages postés 9 Date d'inscription lundi 21 février 2005 Statut Membre Dernière intervention 6 mars 2013
6 mars 2013 à 08:30
Un grand merci pour cette réponse !!
0
Rejoignez-nous