IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

upload d'un fichier


Sujet :

PHP & Base de données

  1. #1
    Membre averti
    Homme Profil pro
    retraité
    Inscrit en
    Mars 2020
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Mars 2020
    Messages : 20
    Par défaut upload d'un fichier
    Bonjour
    Lorsque j'affiche le code source de ma page html d'un fichier uplodé j'ai ces alertes alors que tout s'effectue correctement:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    Array
    (
    )
    <br />
    <b>Warning</b>:  Undefined array key "pdf" in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>25</b><br />
    <br />
    <b>Warning</b>:  Undefined array key "pdf" in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>26</b><br />
    <br />
    <b>Warning</b>:  Trying to access array offset on value of type null in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>26</b><br />
    <br />
    <b>Warning</b>:  Undefined array key "pdf" in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>27</b><br />
    <br />
    <b>Warning</b>:  Trying to access array offset on value of type null in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>27</b><br />
    <br />
    <b>Deprecated</b>:  move_uploaded_file(): Passing null to parameter #1 ($from) of type string is deprecated in <b>C:\xampp\htdocs\marche\gpx\ressources\serveur\FonctionsServeur.php</b> on line <b>28</b><br />
    le code analysé -> $_FILES des 2 "print_r"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Array ( [pdf] => Array ( [name] => poeme_hewaien.pdf [full_path] => poeme_hewaien.pdf [type] => application/pdf [tmp_name] => C:\xampp\tmp\phpFBFA.tmp [error] => 0 [size] => 1384535 ) )
     Array ( [name] => poeme_hewaien.pdf [full_path] => poeme_hewaien.pdf [type] => application/pdf [tmp_name] => C:\xampp\tmp\phpFBFA.tmp [error] => 0 [size] => 1384535 )
    le code d'acquisition du fichier, $type est bien égal à "pdf"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    //Téléchargement fichier
    function upload($path,$type){
    	if($type == 'gpx' || $type == 'png' || $type == 'pdf' || $type == 'xlsx'){
    		print_r($_FILES);
    		print_r($_FILES[$type]);
    		$fichier = $_FILES[$type]['name'];
    		$temp_name = $_FILES[$type]['tmp_name'];
    		if(move_uploaded_file($temp_name, $path."/".$fichier)){
    			rename($path."/".$fichier, str_replace("_","-",$path."/".$fichier));
    			$info = "Fichier enregistré:".$fichier;
    		}else{
    			$info = "Enregistrement Nok";}
    	}
    	else{
    		$info = "Enregistrement Nok";}
    return $info;
    }
    Je suis un peu perdu si vous pouviez m'aiguiller merci.

  2. #2
    Membre émérite
    Homme Profil pro
    Autre
    Inscrit en
    Juillet 2021
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Autre

    Informations forums :
    Inscription : Juillet 2021
    Messages : 472
    Par défaut
    Bonjour,

    Il semble que ton code est exécuté 2 fois : une première fois où l'upload s'effectue correctement et une seconde fois où la superglobale $_FILES est vide (d'où le Array() vide et les warning).

    Il faudrait en savoir plus sur le fil d'exécution de ton code.
    Est-ce qu'il y a une redirection effectuée après l'upload ?
    Où et comment est appelé ta fonction upload(), avec quels contrôles (vérifier si $_FILES est vide par exemple) ?

  3. #3
    Membre averti
    Homme Profil pro
    retraité
    Inscrit en
    Mars 2020
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Mars 2020
    Messages : 20
    Par défaut
    bonjour
    Ca fait un moment que je galère et teste et reteste mais toujours pareil. Donc finalement j'ai rajouté un test sizof($_FILES) qui s'il est à 0 sort de la boucle.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
     
    	switch($choix){
    		case 0:
     
    			break;
    		case 1:
    			//Accueil connexion
    			break;
    		case 2:
    			//Enregistrer GPX
    			if(sizeof($_FILES)===0){break;}
    			$type = $_POST['ext'];
    			$info = upload($dir."/".$rep0."/".$rep1,$type);
    			//traitement via géoservice via ajax
    			if(strpos($info,'.gpx')>0){
    				$file = explode(':',$info)[1];
    				$onload = 'onload=conformation(\''.$rep1.'\',\''.$file.'\');';}
    			break;			
    		case 3:
    			//Mise à jour des points de rendez-vous
    			$contenu = RESSOURCES\parking($pdo);
    			break;	
    		case 4:
    			//Créer répertoire
    			$dir1 = $dir."/".$_POST['rep0']."/".$_POST['repnvx'];
    			$info = mkdir($dir1);
    			break;	
    		case 5:
    			//Suppression fichier -> transfert dans la corbeille
    			$dir1 = $dir."/".$_POST['rep0']."/".$_POST['rep1'];
    			$fichier = $_POST['fichier'];
    			$dir2 = $dir."/corbeille";
    			if($fichier<>'')
    				{$info = rename($dir1."/".$fichier, $dir2.'/'.$fichier);}
    			break;	
    		case 6:
    			//renommer fichier
    			$dir1 = $dir."/".$_POST['rep0']."/".$_POST['rep1'];
    			$fichier = $_POST['fichier'];
    			$rename = $_POST['rename'];
    			if($fichier<>'' && $rename <> '')
    				{$info = rename($dir1."/".$fichier, $dir1."/".$rename);}
    			break;
    		case 7:
    			//Déplacer fichier
    			$dir1 = $dir."/".$_POST['rep0']."/".$_POST['rep1'];
    			$fichier = $_POST['fichier'];
    			$dir2 = $dir."/".$_POST['rep0']."/".$_POST['rep2'];
    			if($fichier<>'')
    				{$info = rename($dir1."/".$fichier, $dir2."/".$fichier);}
    			break;	
    		case 8:
    			//Vider la corbeille
    			$dir1 = $dir."/corbeille/";
    			$fichier = $_POST['fichier'];
    			if($fichier<>'')
    				{if(unlink($dir1.$fichier)){
    					$info = "Fichier supprim&eacute;";}
    				else{
    					$info = "Impossible d'effacer le fichier:".substr(sprintf("%o", fileperms($dir1.$fichier)),-4)."<br>->".ftp_pwd($ftp);
    					}
    				}
    			break;	
    		case 9:
    			//Enregistrer fichier excel
    			if(sizeof($_FILES)===0){break;}
    			$type = $_POST['ext'];
    			$info = upload($dir."/".$rep0,$type);
    			if($type == 'xlsx'){
    				//Fichier adhérents -> transfert dans la Bdd -> tbl adherent
    				$info = transfert_xlsx($pdo, str_replace('Fichier enregistré:','',$info),$chp);
    				}
    			break;
    		case 10:
    			//Enregistrer PDF
    			if(sizeof($_FILES)===0){break;}
    			$type = $_POST['ext'];
    			$info = upload($dir."/".$rep0,$type);
    			break;
    		case 11:
    			//Enregistrer GPX mobile
    			$type = $_POST['ext'];
    			$info = upload($dir."/".$rep0."/".$rep1,$type);
    			$fichier = explode(':',$info)[1];
    			//renommage du fichier
    			if($_POST['rename'] <> ''){
    				$rename = $_POST['rename'];
    				//echo $dir."/".$rep0."/".$rep1."/".$fichier.'  --  '.$dir."/".$rep0."/".$rep1."/".$rename;
    				$info .= rename($dir."/".$rep0."/".$rep1."/".$fichier, $dir."/".$rep0."/".$rep1."/".$rename);
    				$fichier = $rename;}
    			//traitement via géoservice via ajax
    			if(strpos($info,'.gpx')>0){
    				//echo 'onload=conformation(\''.$rep1.'\',\''.$fichier.'\');';
    				//altimetrie($ville,$fichier);
    				$onload  = "const url = './ressources/serveur/conformationGpx.php?rep=$rep1&file=$fichier';"."\n";
    				$onload .= "window.addEventListener('load',surface())";
    			}
    			break;
    	}
    Ce n'est pas top mais ça marche. Avec le temps je finirai par trouver le bug.

  4. #4
    Membre chevronné
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2022
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 22
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2022
    Messages : 408
    Par défaut
    Bonjour,

    Au lieu de dl ton fichier.
    Tu enlèves ca et tu rajoutes full var_dump pour comprendre pk y en a un qui est a 0.


    cdt,
    Un problème sans solution est un problème mal posé. (Albert Einstein)

  5. #5
    Membre averti
    Homme Profil pro
    retraité
    Inscrit en
    Mars 2020
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Mars 2020
    Messages : 20
    Par défaut
    désolé j'ai pas décodé ta réponse

  6. #6
    Membre chevronné
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2022
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 22
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2022
    Messages : 408
    Par défaut
    Met des var_dump
    Un problème sans solution est un problème mal posé. (Albert Einstein)

Discussions similaires

  1. [Upload] Droits des fichiers
    Par flexx dans le forum Langage
    Réponses: 7
    Dernier message: 01/12/2005, 20h14
  2. [Upload] telecherger un fichier
    Par fraizas dans le forum Langage
    Réponses: 2
    Dernier message: 17/11/2005, 17h35
  3. Réponses: 6
    Dernier message: 06/10/2005, 21h54
  4. [Servlet][Tomcat] Upload d'un fichier sur le serveur
    Par gandalf_le_blanc dans le forum Tomcat et TomEE
    Réponses: 7
    Dernier message: 19/04/2004, 14h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo