Page 1 sur 1
Download fichier excel depuis un select
Posté : 15 sept. 2005, 14:26
par popysan
Bonjour,
J'ai un formulaire qui permet grâce à un select de choisir un fichier excel à télécharger, et je souhaiterais qu'après la validation de ce choix la fenêtre de téléchargement s'ouvre. Avec fopen le fichier excel s'ouvre dans la page html et c'est un vrai charabia !
J'ai essayé plusieur codes :
<?php
if(isset($envoyer))
{
$file="../Planning/".$file.".xls";
if(is_file($file))
{
$fn=fopen($file , "r+");
}
else
{
echo "le fichier '".$file."' n'est pas valide ou n'existe pas";
}
}
?>
Et voici le message d'erreur que j'obtiens :
Warning: fopen(../Planning/planning_01_09_2005.xls): failed to open stream: Permission denied in /vh/jouy/htdocs/unites/ucea/Bureau/planning.php on line 133
Si je mets le chemin complet : "le fichier n'est pas valide ou n'existe pas"
Je débute en php et donc je tatonne un peu ! Si quelqu'un peut m'aider, je l'en remercie d'avance.
Posté : 15 sept. 2005, 14:38
par ouckileou
tu peux forcer le téléchargement (faire apparaitre une fenêtre) avec les headers
voici un exemple pioché sur le net, à tester
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header('Content-Type: application/force-download');
header("Pragma: no-cache");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
header("Expires: 0");
il y a aussi un content-type spécifique à Excel il me semble, au lieu de "application/octet-stream"
sinon pour tes problèmes, soit le chemin que tu entres n'est pas bon, il faudrait donc le faire afficher pour le vérifier, soit tu n'as pas les dorits d'accéder au fichier
Posté : 15 sept. 2005, 15:08
par popysan
Voilà ce que j'obtiens à ajoutant les header.
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau//Planning.php on line 126
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau//Planning.php on line 127
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php on line 128
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php on line 129
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php on line 130
Warning: Cannot modify header information - headers already sent by (output started at /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php:12) in /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php on line 131
Warning: fopen(../Planning/planning_01_09_2005.xls): failed to open stream: Permission denied in /vh/jouy/htdocs/unites/ucea/Bureau/Planning.php on line 132
En ce qui concerne le chemin je l'ai affiché, puis je l'ai utilisé comme url, et mon fichier excel s'est ouvert.
Je ne comprend vraiment pas où ça coince ! Merci de ton aide.
Posté : 15 sept. 2005, 15:18
par ouckileou
c'est surement qu'il y a du texte envoyé au navigateur, les messages d'erreur par exemple
laisse les headers de coté pour le moment alors
donc quand tu affiches $file c'est le bon chemin ? mais il refuse le fopen() ?
Posté : 15 sept. 2005, 15:31
par popysan
En fait si je met ce chemin :
../Planning/planning_01_09_2005.xls
il m'affiche ceci
Warning: fopen(../Planning/planning_01_09_2005.xls): failed to open stream: Permission denied in /vh/jouy/htdocs/unites/ucea/Bureau/planning.php on line 132
et si je met le chemin complet :
http://www.xxx/unites/ucea/Planning/pla ... 9_2005.xls
il ne se passe rien !
Posté : 15 sept. 2005, 15:39
par popysan
en fait si je mets le chemin complet en dur, il ne rentre pas dans la boucle
if(is_file($file)) et m'affiche donc que le fichier n'est pas valide, alors que si je met le même chemin comme url ça marche !
Posté : 15 sept. 2005, 16:22
par ouckileou
tu es sûr que le chemin relatif est bon alors ?
Posté : 15 sept. 2005, 16:28
par popysan
oui, mais effectivement c'est bizarre que je n'ai pas le même résultat qu'avec le chemin complet, dans les deux cas ça ne marche pas donc il y a autre chose.
Posté : 15 sept. 2005, 16:33
par ouckileou
un problème au niveau des majuscules/minuscules ?
sinon je ne vois pas c'est très bizarre si tes chemins sont vraiments bons
et ce n'est pas un problème de droits c'est sûr ?
Posté : 15 sept. 2005, 16:38
par popysan
non sinon ça ne marcherait pas quand je copie le chemin dans l'url de mon navigateur.
merci quand même pour tout !
Posté : 17 nov. 2005, 13:24
par mere-teresa
En fait si je met ce chemin :
../Planning/planning_01_09_2005.xls
il m'affiche ceci
Warning: fopen(../Planning/planning_01_09_2005.xls): failed to open stream: Permission denied in /vh/jouy/htdocs/unites/ucea/Bureau/planning.php on line 132
et si je met le chemin complet :
http://www.xxx/unites/ucea/Planning/pla ... 9_2005.xls
il ne se passe rien !
/vh/jouy/htdocs/unites/ucea/Bureau/ différent de http://www.xxx/unites/ucea/Planning/
Il y le répertoire Bureau au milieu !